Identify a number’s direction with sign
sign(x) returns -1 for a negative value, 0 for zero, and 1 for a positive value. It is useful in piecewise formulas, direction vectors, and threshold logic.
Example
sign(-4.2) is -1. Pair it with abs to separate magnitude from direction, or use isPositive and isNegative when a Boolean test is clearer.
Caveats
Near-zero floating-point values may not be exactly zero; define a tolerance in measurement workflows. Complex numbers do not have the same simple ordering as reals. Use compare for pairwise ordering of suitable values.