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

abs(+Number, ?Result)

Unifies the absolute value of Number with Result.
+Number
A number.
?Result
A variable or a number.

Description

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

Number and Result have to be of the same type.

In coroutining mode, if Number is a free variable, the call to abs/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
Result and Number are numbers of different types.
(24) number expected
Number is not of a numeric type.
(24) number expected
Result is neither a number nor a variable.

Examples

Success:
      abs(1, 1).
      abs(-5, Result).             (gives Result = 5)
      abs(-6.2, Result).           (gives Result = 6.2)
Fail:
      abs(1, 0).
Error:
      abs(A, 6).                   (Error 4).
      abs(1, 1.0).                 (Error 5).
      abs(-1.0, 1).                (Error 5).
      abs(4 + 2, 6).               (Error 24).
      abs(1, r).                   (Error 24).



See Also

is / 2