2.16.1.6 NaN and Infinity floats and their syntax
SWI-Prolog supports reading an printing `special' floating point values according to Proposal for Prolog Standard core update wrt floating point arithmetic by Joachim Schimpf and available in ECLiPSe Prolog. In particular,
- Infinity is printed as
1.0Inf
or-1.0Inf
. Any sequence matching the regular expression[+-]?\sd+[.]\sd+Inf
is mapped to plus or minus infinity. NaN
(Not a Number) is printed as1.xxxNaN
, where 1.xxx is the float after replacing the exponent by `1'. Such numbers are read, resulting in the sameNaN
. TheNaN
constant can also be produced using the function nan/0, e.g.,?- A is nan. A = 1.5NaN.
Note that, compliant with the ISO standard, SWI-Prolog arithmetic (see section 4.27) never returns one of the above values but instead raises an exception, e.g.,
?- A is 1/0. ERROR: //2: Arithmetic: evaluation error: `zero_divisor'
There is one exception to this rule. For compatibility the functions
inf/0 and nan/0
return 1.0Inf
and the default system NaN
. The
ability to create, read and write such values is primarily provided to
exchange data with languages that can represent the full range of IEEE
doubles.