We supply a number of binary and unary operations that deal with rounding. We find different rounding modes and we also find different forms of division. The result type of the evaluable function integer/1 is always an integer. On the other hand the result type of the evaluable functions truncate/1, floor/1, ceiling/1 and round/1 is the same as the argument type:
integer: integer towards zeroExamples:
truncate: towards zero
floor: towards lower infinity
ceiling: towards upper infinity
round: towards nearest neighbour or then away from zero
floor(-3) --> -3
floor(-3.14) --> -4.0
floor(-0d3.1415) --> -0d4
The division is based on a hypothetical /F operation. This operation is approximate for float arguments and exact for integer and decimal arguments. The result type of the evaluable functions (//)/2 and (div)/2 is always an integer. On the other hand the result type of the eval-uable functions (rem)/2 and (mod)/2 is the same as the argument types:
X // Y = integer(X / Y).Examples:
X div Y = integer(floor(X / Y)).
X rem Y = X – (X // Y) * Y.
X mod Y = X – (X div Y) * Y.
5 // 2 --> 2
5.0 // 2.0 --> 2
0d5.00 // 2 --> 2
(-5) // 2 --> -2
(-5) div 2 --> -3
5 rem 2 --> 1
5.0 rem 2.0 --> 1.0
0d5.00 rem 2 --> 0d1.00
(-5) rem 2 --> -1
(-5) mod 2 --> 1
If the arguments of the binary operations have different types the same widening as already defined for the basic operations is applied. This means the widening is done towards the bigger domain of the two arguments.
The following rounding operations are recognized in evaluations:
The following Prolog flags for rounding operations are provided: