MathLib.sign()

MathLib.sign is an implementation of the sign function: \[ \text{MathLib.sign}(x) = \begin{cases} -1 & \text{if } x < 0, \\ 0 & \text{if } x = 0, \\ 1 & \text{if } x > 0. \end{cases} \]

Specification

MathLib.tanh accepts one argument. Any additional arguments will be ignored. The type of the argument should be number. For other argument types see the unary function specification.
  1. MathLib.sign(NaN) = NaN
  2. MathLib.sign(0) = 0
  3. MathLib.sign(-0) = -0
  4. MathLib.sign(x) = 1 for x > 0
  5. MathLib.sign(x) = -1 for x < 0

Possible issues

MathLib uses the normal mathematical convention of setting the value at 0 to 0: \[ \text{MathLib.sign}(0) = 0 \] In some cases it it may be neccessary to set \[ \text{sign}(0) = 1; \] To achieve this, you can use the following function:

Tests

Categories: unary Function