Availability:Arithmetic function (see is/2)
rationalize(+Expr)Convert the Expr to a rational number or integer. The
function is similar to rational/1,
but the result is only accurate within the rounding error of floating
point numbers, generally producing a much smaller denominator.130The
names rational/1
and rationalize/1
as well as their semantics are inspired by Common Lisp.131The
implementation of rationalize as well as converting a rational number
into a float is copied from ECLiPSe and covered by the Cisco-style
Mozilla Public License Version 1.1.
?- A is rationalize(0.25).
A = 1r4
?- A is rationalize(0.1).
A = 1r10
For every normal float X the relation
X =:=
rationalize(X)
holds.
This function raises the same exceptions as rational/1
on non-normal floating point numbers.