Availability:Arithmetic function (see is/2)
rational(+Expr)Convert the Expr to a rational number or integer. The
function returns the input on integers and rational numbers. For
floating point numbers, the returned rational number exactly
represents the float. As floats cannot exactly represent all decimal
numbers the results may be surprising. In the examples below, doubles
can represent 0.25 and the result is as expected, in contrast to the
result of rational(0.1)
. The function rationalize/1
remedies this. See section
4.27.2.2 for more information on rational number support.
?- A is rational(0.25).
A is 1r4
?- A is rational(0.1).
A = 3602879701896397r36028797018963968
For every normal float X the relation
X =:=
rational(X) holds.
This function raises an evaluation_error(undefined)
if Expr
is NaN and evaluation_error(rational_overflow)
if Expr
is Inf.