Function Sign(x)

Sign

Sign(
    x             ! (input) numerical expression
    )

Arguments

x

A scalar numerical expression.

Return Value

The function Sign returns \(+1\) if \(x > 0\), \(-1\) if \(x < 0\) and 0 if \(x = 0\).

Example

_p_returnM1 := Sign(-3); ! returns -1. Sign of negative value is -1.
_p_returnZ  := Sign( 0); ! returns  0. Sign of 0.0 is 0.0
_p_returnP1 := Sign( 3); ! returns  1. Sign of positive value is 1.

Note

The function Sign can be used in constraints of nonlinear mathematical programs. However, nonlinear solver may experience convergence problems round 0.

See also

The function Abs. Arithmetic functions are discussed in full detail in Arithmetic Functions of the Language Reference.