Algosim documentation: sgn

sgn

The sign (signum) function.

Syntax

Description

For real x, sgn(x) is the sign of x:

         ⎧ −1   if x < 0
sgn(x) = ⎨  0   if x = 0
         ⎩ +1   if x > 0.

Typewise, sgn(x) is an integer.

Clearly, for non-zero x,

sgn(x) = x/abs(x)

which motivates the definition of sgn(z) for complex z:

sgn(z) = z/abs(z) if z ≠ 0
sgn(0) = 0.

Typewise, sgn(z) is a complex number.

Examples

sgn(1 + i)
0.707106781187 + 0.707106781187⋅i
collapse(SequenceVector(1000) @ Mertens @ sgn)
(1, 1)
(0, 1)
(−1, 36)
(0, 2)
(−1, 17)
(0, 1)
(−1, 6)
(0, 1)
(−1, 27)
(0, 1)
(1, 7)
⋮

See also