Commit 174b13ae authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Handle any exponant, add a try_to_cast_integer in util

parent 519168fe
......@@ -61,6 +61,7 @@
% Only for separate compilation/linking
:- use_module(doc).
:- use_module(reaction_rules).
:- use_module(util).
:- use_module(library(yall)).
:- op(1010, fx, init). % comma is 1000
......@@ -1420,9 +1421,10 @@ filter_denominator(X^Nr, Num, Den) :-
(
number(Nr)
->
N = Nr
util:try_to_cast_integer(Nr, N)
;
parameter_value(Nr, N)
parameter_value(Nr, Nt),
util:try_to_cast_integer(Nt, N)
),!,
(
N<0
......@@ -1442,8 +1444,8 @@ filter_denominator(X^Nr, Num, Den) :-
filter_denominator(X, Num, Den)
;
filter_denominator(X, NumT, DenT),
maplist([X,Y]>>(Y = X^N), NumT, Num),
maplist([X,Y]>>(Y = X^N), DenT, Den)
maplist({N}/[X,Y]>>(Y = X^N), NumT, Num),
maplist({N}/[X,Y]>>(Y = X^N), DenT, Den)
).
filter_denominator(X, [X], []).
......
......@@ -957,6 +957,21 @@ atom_to_int(String, Int) :-
read_term_from_atom(String, Int, []),
integer(Int).
%! try_to_cast_integer(+Expr, -Result)
%
% Try to read Expr as an integer and return a float if it is not possible (discrepancy
% higher than 1e-9)
try_to_cast_integer(Expr, Result) :-
Putative_Float is Expr,
Putative_Int is integer(Putative_Float),
Discr is abs((Putative_Int-Putative_Float)/Putative_Float),
(
Discr < 1e-9
->
Result = Putative_Int
;
Result = Putative_Float
).
% what setof should have always been
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment