Some progress in supporting floats
Fixed some typos
This commit is contained in:
parent
3af7f72aa4
commit
d054989bc0
37
polymani.pl
37
polymani.pl
@ -261,7 +261,6 @@ do_process_input(store_multiplication(TN, PT, V)) :-
|
|||||||
write(SP),
|
write(SP),
|
||||||
nl.
|
nl.
|
||||||
do_process_input(multiply(TN, PT)) :-
|
do_process_input(multiply(TN, PT)) :-
|
||||||
%% To multiply, assume the left is a number
|
|
||||||
%% Flatten both
|
%% Flatten both
|
||||||
polynomial_tree_to_polynomial(TN, N),
|
polynomial_tree_to_polynomial(TN, N),
|
||||||
polynomial_tree_to_polynomial(PT, P),
|
polynomial_tree_to_polynomial(PT, P),
|
||||||
@ -445,18 +444,30 @@ parse_number_explicit(_, T, T, [], []) :-
|
|||||||
%
|
%
|
||||||
% Parse a floating point number
|
% Parse a floating point number
|
||||||
%
|
%
|
||||||
|
parse_floating_number(N) -->
|
||||||
|
{
|
||||||
|
not(compound(N))
|
||||||
|
},
|
||||||
|
[N],
|
||||||
|
{
|
||||||
|
% Assert it must be between negative and positive infinity
|
||||||
|
% This uses the CLPR library, which makes this reversible,
|
||||||
|
% whereas `number(N)` is always false, since it only succeeds
|
||||||
|
% if the argument is bound (to a integer or float)
|
||||||
|
(N >= 0; N < 0)
|
||||||
|
}.
|
||||||
parse_floating_number(op('.', TL, TR)) -->
|
parse_floating_number(op('.', TL, TR)) -->
|
||||||
%% A float is a node with a dot as the operator
|
%% A float is a node with a dot as the operator
|
||||||
%% If there's a number on the left
|
%% If there's a number on the left
|
||||||
parse_number(TL),
|
parse_number(TL),
|
||||||
%% Followed by either point or dot
|
%% Followed by either point or dot
|
||||||
[X],
|
[RadixPoint],
|
||||||
{ member(X, [point, dot]), ! },
|
{
|
||||||
|
member(RadixPoint, [point, dot]),
|
||||||
|
!
|
||||||
|
},
|
||||||
%% Followed by another number
|
%% Followed by another number
|
||||||
parse_positive_number(TR).
|
parse_positive_number(TR).
|
||||||
parse_floating_number(TN) -->
|
|
||||||
%% Or just a number
|
|
||||||
parse_number(TN).
|
|
||||||
|
|
||||||
%% parse_positive_number(-tree, +stream, -not_consumed) is det
|
%% parse_positive_number(-tree, +stream, -not_consumed) is det
|
||||||
%
|
%
|
||||||
@ -464,8 +475,11 @@ parse_floating_number(TN) -->
|
|||||||
%
|
%
|
||||||
parse_positive_number(N) -->
|
parse_positive_number(N) -->
|
||||||
[N],
|
[N],
|
||||||
%% CLPFD, a number between 0 and infinity
|
{
|
||||||
{ N in 0..sup, ! }.
|
not(compound(N)),
|
||||||
|
%% CLPFD, a number between 0 and infinity
|
||||||
|
N in 0..sup, !
|
||||||
|
}.
|
||||||
parse_positive_number(T) -->
|
parse_positive_number(T) -->
|
||||||
parse_number_explicit(void, void, T).
|
parse_number_explicit(void, void, T).
|
||||||
|
|
||||||
@ -476,7 +490,7 @@ parse_positive_number(T) -->
|
|||||||
parse_number(N) -->
|
parse_number(N) -->
|
||||||
[N],
|
[N],
|
||||||
%% CLPFD, a number between negative infinity and positive infinity
|
%% CLPFD, a number between negative infinity and positive infinity
|
||||||
{ not(atom(N)), N in inf..sup, ! }.
|
{ N in inf..sup, ! }.
|
||||||
parse_number(op(neg, T)) --> % TODO
|
parse_number(op(neg, T)) --> % TODO
|
||||||
%% A number can start with negative, to negate it
|
%% A number can start with negative, to negate it
|
||||||
[negative],
|
[negative],
|
||||||
@ -574,6 +588,7 @@ parse_polynomial_operand(load(T)) -->
|
|||||||
|
|
||||||
%% Declare polynomial_store as a dynamic predicate with two arguments
|
%% Declare polynomial_store as a dynamic predicate with two arguments
|
||||||
%% Used to store and retrieve polynomials associated with a variable
|
%% Used to store and retrieve polynomials associated with a variable
|
||||||
|
%% First being the variable name and the second its content
|
||||||
:- dynamic polynomial_store/2.
|
:- dynamic polynomial_store/2.
|
||||||
|
|
||||||
%% parse_stored_variable(-var) is det
|
%% parse_stored_variable(-var) is det
|
||||||
@ -624,7 +639,7 @@ parse_polynomial_variable(B) -->
|
|||||||
% Parse a polynomial. Delegates to explicit variant
|
% Parse a polynomial. Delegates to explicit variant
|
||||||
%
|
%
|
||||||
parse_polynomial(T) -->
|
parse_polynomial(T) -->
|
||||||
%% Ignore "polynomail", if followed by a valid polynomial
|
%% Ignore "polynomial", if followed by a valid polynomial
|
||||||
[polynomial],
|
[polynomial],
|
||||||
{ ! },
|
{ ! },
|
||||||
%% Delegate
|
%% Delegate
|
||||||
@ -809,7 +824,7 @@ parse_command(op(+, TN, TP)) -->
|
|||||||
|
|
||||||
%% parse_input(-tree) is det
|
%% parse_input(-tree) is det
|
||||||
%
|
%
|
||||||
% Parse each command and string it into a list
|
% Parse each command and string into a list
|
||||||
%
|
%
|
||||||
parse_input(command(TCL, TCR)) -->
|
parse_input(command(TCL, TCR)) -->
|
||||||
%% Result is a struct with a command on the left
|
%% Result is a struct with a command on the left
|
||||||
|
Reference in New Issue
Block a user