Sign¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Sign[x] gives -1, 0, or 1 for real numeric x according to its sign, and z/Abs[z] for a nonzero numeric complex z.
Examples¶
No verified examples yet for this function.
Implementation notes¶
builtin_sign returns the sign (-1/0/1) of a real number — direct comparisons for EXPR_INTEGER/EXPR_REAL (and Rational by sign of numerator×denominator), mpz_sgn for BigInt, mpfr_sgn for MPFR. For a numeric Complex[re, im] with both parts numeric it returns the unit-modulus direction z/Abs[z] (short-circuiting 0+0I -> 0); MPFR components take a fast path computing the direction directly via mpfr_hypot and division at the combined working precision rather than building the symbolic z·Power[Abs[z], -1] tree. Non-numeric arguments return NULL (unevaluated).
Attributes: Listable, NumericFunction, Protected.
Implementation status¶
Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
References¶
- Source:
src/complex.c - Specification:
docs/spec/builtins/arithmetic.md
Notes & additional examples¶
Worked examples¶
Notes¶
For real x, Sign[x] is -1, 0, or 1. For a nonzero complex z it returns the unit-modulus direction z/Abs[z]: (1+I)^2 = 2I points straight up the imaginary axis (I), while 2 - 2I lies on the diagonal and returns the exact unit vector (1 - I)/Sqrt[2]. Sign is Listable.