|Did you know ...||Search Documentation:|
SWI-Prolog defines the following numeric types:
Internally, SWI-Prolog has three integer representations. Small integers (defined by the Prolog flag max_tagged_integer) are encoded directly. Larger integers are represented as 64-bit values on the global stack. Integers that do not fit in 64 bits are represented as serialised GNU MPZ structures on the global stack.
rdiv(N,M). Rational numbers that are returned from is/2 are canonical, which means M is positive and N and M have no common divisors. Rational numbers are introduced in the computation using the rational/1, rationalize/1 or the rdiv/2 (rational division) function. Using the same functor for rational division and for representing rational numbers allows for passing rational numbers between computations as well as for using format/3 for printing.
In the long term, it is likely that rational numbers will become
atomic as well as a subtype of number. User code that
creates or inspects the
rdiv(M,N) terms will not be
portable to future versions. Rationals are created using one of the
functions mentioned above and inspected using rational/3.
double. On most of today's platforms these are 64-bit IEEE floating point numbers.
Arithmetic functions that require integer arguments accept, in addition to integers, rational numbers with (canonical) denominator `1'. If the required argument is a float the argument is converted to float. Note that conversion of integers to floating point numbers may raise an overflow exception. In all other cases, arguments are converted to the same type using the order below.
integer -> rational number -> floating point number