- Documentation
- Reference manual
- Built-in Predicates
- Arithmetic
- General purpose arithmetic
- Arithmetic Functions
- -/1
- +/1
- +/2
- -/2
- */2
- //2
- mod/2
- rem/2
- ///2
- div/2
- rdiv/2
- gcd/2
- lcm/2
- abs/1
- sign/1
- copysign/2
- nexttoward/2
- roundtoward/2
- max/2
- min/2
- ./2
- random/1
- random_float/0
- round/1
- integer/1
- float/1
- rational/1
- rationalize/1
- numerator/1
- denominator/1
- float_fractional_part/1
- float_integer_part/1
- truncate/1
- floor/1
- ceiling/1
- ceil/1
- >>/2
- <</2
- \//2
- /\/2
- xor/2
- \/1
- sqrt/1
- sin/1
- cos/1
- tan/1
- asin/1
- acos/1
- atan/1
- atan2/2
- atan/2
- sinh/1
- cosh/1
- tanh/1
- asinh/1
- acosh/1
- atanh/1
- log/1
- log10/1
- exp/1
- **/2
- ^/2
- powm/3
- lgamma/1
- erf/1
- erfc/1
- pi/0
- e/0
- epsilon/0
- inf/0
- nan/0
- cputime/0
- eval/1
- msb/1
- lsb/1
- popcount/1
- getbit/2
- Arithmetic Functions
- General purpose arithmetic
- Arithmetic
- Built-in Predicates
- Packages
- Reference manual
Availability:Arithmetic function (see is/2)
true
or one of the arguments is a float, both arguments are converted to
float and the return value is a float. Otherwise the result type depends
on the Prolog flag
prefer_rationals.
If true
, the result is always a rational number. If false
the result is rational if at least one of the arguments is rational.
Otherwise (both arguments are integer) the result is integer if the
division is exact and float otherwise. See also section
4.27.2.2, ///2, and rdiv/2.
The current default for the Prolog flag prefer_rationals
is
false
. Future version may switch this to true
,
providing precise results when possible. The pitfall is that in general
rational arithmetic is slower and can become very slow and produce huge
numbers that require a lot of (global stack) memory. Code for which the
exact results provided by rational numbers is not needed should force
float results by making one of the operants float, for example by
dividing by
10.0
rather than 10
or by using float/1.
Note that when one of the arguments is forced to a float the division is
a float operation while if the result is forced to the float the
division is done using rational arithmetic.