Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lifeware
biocham
Commits
174b13ae
Commit
174b13ae
authored
Jul 01, 2020
by
Mathieu Hemery
Browse files
Handle any exponant, add a try_to_cast_integer in util
parent
519168fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
ode.pl
View file @
174b13ae
...
...
@@ -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
=
N
r
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
],
[]).
...
...
util.pl
View file @
174b13ae
...
...
@@ -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
<
1
e
-
9
->
Result
=
Putative_Int
;
Result
=
Putative_Float
).
% what setof should have always been
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment