<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 * Copyright (C) 2015, 2016, 2018 - Samuel GOUGEON
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
        xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
        xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
        xmlns:scilab="http://www.scilab.org" xml:id="sign" xml:lang="en">
    <refnamediv>
        <refname>sign</refname>
        <refpurpose>signum function</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>X = sign(A)</synopsis>
    </refsynopsisdiv>
    <refsection role="parameters">
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>А</term>
                <listitem>
                    <para>
                        matrix of encoded integers, decimal numbers, or complex numbers.
                        <varname>A</varname> may be sparse.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>X</term>
                <listitem>
                    <para>
                        matrix of the same size and data type as <varname>A</varname>.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection role="description">
        <title>Description</title>
        <para>
            If <varname>X</varname> are integers or real numbers,
            <itemizedlist>
                <listitem>
                    <literal>X(i) = -1</literal> where <literal>A(i)&lt;0</literal>
                </listitem>
                <listitem>
                    <literal>X(i) = 0</literal> where <literal>A(i)==0</literal>
                </listitem>
                <listitem>
                    <literal>X(i) = 1</literal> where <literal>A(i)>0</literal>
                </listitem>
                <listitem>
                    <literal>X(i)= %nan</literal> where <literal>A(i)</literal> is NaN.
                </listitem>
            </itemizedlist>
        </para>
        <para>
            If <varname>X</varname> is complex encoded: <literal>sign(A==0) = 0</literal>.
            Elsewhere, <literal>sign(A) = A./abs(A)</literal>.
        </para>
    </refsection>
    <refsection role="examples">
        <title>Examples</title>
        <para>With decimal numbers:</para>
        <programlisting role="example"><![CDATA[
m  = [ 1.25  -2.5  -%inf   2.75
       0.     1.    0.75   %inf
       %nan   0.   -1.5   -2.5 ]; m
sign(m)
 ]]></programlisting>
    <screen><![CDATA[
--> 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.
]]></screen>
    <para>With complex numbers:</para>
    <programlisting role="example"><![CDATA[
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)
 ]]></programlisting>
    <screen><![CDATA[
--> 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
]]></screen>
    <para>With a sparse matrix:</para>
    <programlisting role="example"><![CDATA[
sign(sprand(8,3,0.3,"normal"))
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="abs">abs</link>
            </member>
            <member>
                <link linkend="csgn">csgn</link>
            </member>
            <member>
                <link linkend="signm">signm</link>
            </member>
        </simplelist>
    </refsection>
    <refsection role="history">
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>6.0</revnumber>
                <revdescription>Extension to sparse matrices
                </revdescription>
            </revision>
        </revhistory>
    </refsection>
</refentry>
