sign
result = sign(x)
Input: x · Output: result
What it is
The sign of each element, using Rust's f64::signum semantics: -1 for a negative value (including -0.0), +1 for a non-negative value (including +0.0 — so sign(0) returns 1, never 0, a real edge case worth knowing about), and NaN for a NaN input. x is a scalar, Vec, or Mat/Signal.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = sign(x) | x scalar, Vec, Mat, or Signalnot documented yet | result — | Returns exactly the same type and shape as x, one sign per element. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
print(sign([-2, -0.5, 0.5, 2])) # [-1, -1, 1, 1] — sign(0) would be +1, never 0
output
[-1, -1, 1, 1]
from core-math