[ Arithmetic | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]

integer(+Number, -Result)

Convert an integral number of any type to an integer
A number.
A variable or integer.


This predicate is used by the ECLiPSe compiler to expand evaluable arithmetic expressions. So the call to integer(Number, Result) is equivalent to
    Result is integer(Number)
which should be preferred for portability.

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.

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

Modes and Determinism


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


      X is integer(5.0).               (gives X = 5)

      integer(5, 5).
      integer(5.0, 5).
      integer(5_1, 5).
      integer(5.0__5.0, 5).

      integer(1.1, X).                 (Error 20)
      integer(5_4, X).                 (Error 20)
      integer(0.99__1.01, X).          (Error 20)
      integer(A, 6.0).                 (Error 4).
      integer(0.0, 0.0).               (Error 5).
      integer(4 + 2.3, 6).             (Error 24).
      integer(1, r).                   (Error 24).

See Also

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