[ ECLiPSe Arithmetic built-in.|Group Index| Full Index]

round(+Number, ?Result)

Rounds Number to the nearest integral value of the same type and unifies the resulting real value with Result.

+Number
A number.
?Result
A variable or real.

Description

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

In coroutining mode, if Number is a free variable, the call to round/2 is delayed until this variable is instantiated.

Fail Conditions

Fails if the result of the evaluation does not unify with Result.

Resatisfiable

No

Exceptions

(4) Instantiation fault
Number is not instantiated (non-coroutining mode only).
(5) Type error
Number and Result are numers of different type.
(24) Number expected
Number is not of a numeric type.
(24) Number expected
Result is neither a number nor a variable.

Examples


Success:
      round(1.49, 1.0).
      round(1.5, 2.0).          (odd integer part)
      round(2.5, 2.0).
      round(2.51, 3.0).         (even integer part)
      round(3.5, 4.0).
      round(-6.4, Result).      (gives Result = -6.0)
      round(3, 3).
Fail:
      round(1, 0.0).
Error:
      round(A, 6.0).                   (Error 4).
      round(0.5, 0).                   (Error 5).
      round(4 + 2.3, 6.0).             (Error 24).
      round(1, r).                     (Error 24).


See Also

is / 2