[ Arithmetic | Reference Manual | Alphabetic Index ]
# truncate(+Number, -Result)

Unifies Result with the closest integer value between 0 and
Number, and of the same numeric type as Number.
*Number*
- A number.
*Result*
- A variable or number.

## Description

This predicate is used by the ECLiPSe compiler to expand evaluable
arithmetic expressions. So the call to truncate(Number, Result) is
equivalent to
Result is truncate(Number)

which should be preferred for portability.
This operation works on all numeric types. The result value is the
closest integral value that lies between 0 and Number (rounding
towards zero).

The result type is the same as the argument type. To convert the
type to integer, use integer/2.

In coroutining mode, if Number is uninstantiated, the call to truncate/2
is delayed until this variable is instantiated.

### Modes and Determinism

### Exceptions

*(4) instantiation fault *
- Number is not instantiated (non-coroutining mode only).
*(24) number expected *
- Number is not of a numeric type.

## Examples

Success:
X is truncate(1.8). (gives Result = 1.0)
truncate(1.8, 1.0).
truncate(-1.8, -1.0).
truncate(5, 5).
truncate(-6.4, Result). (gives Result = -6.0)
Fail:
truncate(1.0, 0.0).
truncate(0.5, 0).
truncate(1, r).
Error:
truncate(A, 6.0). (Error 4).
truncate(4 + 2.3, 6.0). (Error 24).

## See Also

is / 2, floor / 2, ceiling / 2, round / 2, integer / 2, fix / 2