sign signum function

## Syntax

    X = sign(A)

## Arguments

А

  matrix of encoded integers, decimal numbers, or complex numbers. `A` may be sparse.

X

  matrix of the same size and data type as `A`.

## Description

If `X` are integers or real numbers,

- `X(i) = -1` where `A(i)<0`
- `X(i) = 0` where `A(i)==0`
- `X(i) = 1` where `A(i)>0`
- `X(i)= %nan` where `A(i)` is NaN.

If `X` is complex encoded: `sign(A==0) = 0`. Elsewhere, `sign(A) = A./abs(A)`.

## Examples

With decimal numbers:

    m  = [ 1.25  -2.5  -%inf   2.75
           0.     1.    0.75   %inf
           %nan   0.   -1.5   -2.5 ]; m
    sign(m)

    --> m  =
       1.25  -2.5  -Inf    2.75
       0.     1.    0.75   Inf
       Nan    0.   -1.5   -2.5

    --> sign(m)
     ans  =
       1.   -1.  -1.   1.
       0.    1.   1.   1.
       Nan   0.  -1.  -1.

With complex numbers:

    i = %i;
    c = [-1, -i, -3+4*i
          1,  i,  3+4*i
          3,  0,  3-4*i
         -4, 4*i,-4-3*i ];
    c
    sign(c)

    --> c  =
      -1.  -i     -3. + 4.i
       1.   i      3. + 4.i
       3.   0.     3. - 4.i
      -4.   4.i   -4. - 3.i

    --> sign(c)
     ans  =
      -1.  -i     -0.6 + 0.8i
       1.   i      0.6 + 0.8i
       1.   0.     0.6 - 0.8i
      -1.   i     -0.8 - 0.6i

With a sparse matrix:

    sign(sprand(8,3,0.3,"normal"))

## See also

- abs
- csgn
- signm

## History

6.0 Extension to sparse matrices