[ Arithmetic | Reference Manual | Alphabetic Index ]

integer(+Number, -Result)

-Result is integer(+Number)

Convert an integral number of any type to an integer
Number
A number.
Result
Output: integer.

Description

Convert an integral number of any type to an integer.

This is a pure type conversion operation. If Number has an integral value of any type, Result is that same value, but represented as an integer. If Number does not have an integral value, an exception is raised. This function should therefore normally be applied to the result of one of the rounding operations floor, ceiling, round or truncate.

This predicate can be used as a function in arithmetic expressions. In coroutining mode, if Number is uninstantiated, the call to integer/2 is delayed until this variable is instantiated.

Modes and Determinism

Exceptions

(4) instantiation fault
Number is not instantiated (non-coroutining mode only).
(5) type error
Number is of type breal.
(20) arithmetic exception
Number is not integral.
(24) number expected
Number is not of a numeric type.

Examples

Success:
    X is integer(5).			% gives X = 5
    X is integer(5.0).			% gives X = 5
    X is integer(5_1).			% gives X = 5
    X is integer(5.0__5.0).		% gives X = 5

Error:
    X is integer(1.1, X).               % arithmetic exception
    X is integer(5_4, X).               % arithmetic exception
    X is integer(0.99__1.01, X).        % arithmetic exception

See Also

is / 2, floor / 2, ceiling / 2, round / 2, truncate / 2