[ Arithmetic | Reference Manual | Alphabetic Index ]
Unifies Result with the sign of Number which is either -1, 0 or 1.
- A number.
- A variable or an integer.
This predicate is used by the ECLiPSe compiler to expand evaluable
arithmetic expressions. So the call to sgn(Number, Result) is
Result is sgn(Number)
which should be preferred for portability.
sgn/2 gives the integer -1 if Number is negative, 0 if it is zero and 1
if it is greater than zero. It is always true that
X =:= sgn(X) * abs(X)
In coroutining mode, if Number is uninstantiated, the call to sgn/2 is
delayed until this variable is instantiated.
Modes and Determinism
- (4) instantiation fault
- Number is not instantiated (non-coroutining mode only).
- (24) number expected
- Number is not of a numeric type.
sgn(-5, Result). (gives Result = -1)
sgn(-6.2, Result). (gives Result = -1)
sgn(A, 6). (Error 4).
sgn(4 + 2, 6). (Error 24).
is / 2