* Bug 15535 fixed: sign(int8(0)) was wrong. sign() page improved 68/19968/5
Stéphane Mottelet [Fri, 20 Apr 2018 10:57:31 +0000 (12:57 +0200)]
  http://bugzilla.scilab.org/15535
  help page (PDF): http://bugzilla.scilab.org/attachment.cgi?id=4714

Change-Id: I097c9879808267240a398ae8c753aa90f12a9b19

scilab/CHANGES.md
scilab/modules/ast/includes/types/int.hxx
scilab/modules/elementary_functions/help/en_US/matrixoperations/sign.xml
scilab/modules/elementary_functions/help/fr_FR/matrixoperations/sign.xml
scilab/modules/elementary_functions/help/ja_JP/matrixoperations/sign.xml [deleted file]
scilab/modules/elementary_functions/help/pt_BR/matrixoperations/sign.xml [deleted file]
scilab/modules/elementary_functions/help/ru_RU/matrixoperations/sign.xml
scilab/modules/elementary_functions/sci_gateway/cpp/sci_sign.cpp
scilab/modules/helptools/data/configuration/scilab_macros.txt
scilab/modules/integer/macros/%i_sign.sci [deleted file]
scilab/modules/integer/tests/nonreg_tests/bug_15535.tst [new file with mode: 0644]

index 2ab56ae..8a1f229 100644 (file)
@@ -430,6 +430,7 @@ Known issues
 * [#15525](http://bugzilla.scilab.org/show_bug.cgi?id=15525): Memory allocation crashed with a simple Scilab script.
 * [#15527](http://bugzilla.scilab.org/show_bug.cgi?id=15527): `ode` gave incorrect results with %ODEOPTIONS(1)=2.
 * [#15528](http://bugzilla.scilab.org/show_bug.cgi?id=15528): savewave wrote null signal if 24 bits resolution and more than 2 channels
+* [#15535](http://bugzilla.scilab.org/show_bug.cgi?id=15535): `sign(int8(0))` returned 1 instead of 0, as well with any other input encoded integer type.
 * [#15539](http://bugzilla.scilab.org/show_bug.cgi?id=15539): zero step in integer implicit list crashed Scilab.
 * [#15548](http://bugzilla.scilab.org/show_bug.cgi?id=15548): [%t %t]./[%f %f] crashed Scilab.
 * [#15549](http://bugzilla.scilab.org/show_bug.cgi?id=15549): unary minus incorrectly acted as the negation operator on %t.
index 29779ea..c1772dc 100644 (file)
@@ -96,7 +96,7 @@ public :
         pbClone->set(ArrayOf<T>::get());
         return pbClone;
     }
-
+    
     /*Config management*/
     void whoAmI();
 
@@ -172,6 +172,18 @@ public :
         memset(this->m_pRealData, 0x00, sizeof(T) * size);
     }
 
+    Int<T>* sign()
+    {
+        Int<T> *pOut = new Int<T>(getDims(), getDimsArray());
+        T* p = pOut->get();
+        int size = getSize();
+        for (int i = 0; i < size; ++i)
+        {
+            p[i] = (m_pRealData[i] > T(0)) - (m_pRealData[i] < T(0));
+        }
+        return pOut;
+    }
+
 protected :
     inline InternalType::ScilabType getType(void);
     inline InternalType::ScilabId   getId(void);
index 5bd036e..78c9b37 100644 (file)
@@ -2,6 +2,7 @@
 <!--
  * Scilab ( http://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
  *
  * 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">
+<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>
                 <term>А</term>
                 <listitem>
                     <para>
-                        real or complex matrix. <varname>A</varname> may be sparse.
+                        matrix of encoded integers, decimal numbers, or complex numbers.
+                        <varname>A</varname> may be sparse.
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>X</term>
                 <listitem>
-                    <para>real or complex matrix</para>
+                    <para>
+                        matrix of the same size and data type as <varname>A</varname>.
+                    </para>
                 </listitem>
             </varlistentry>
         </variablelist>
     <refsection role="description">
         <title>Description</title>
         <para>
-            <literal>X = sign(A)</literal> returns the matrix made of the signs of
-            <literal>A(i,j)</literal>. For complex <literal>A</literal>,
-            <literal>sign(A) = A./abs(A)</literal>.
+            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[
-sign(rand(2,3))
-sign(1+%i)
+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>
index 5ea3c50..720ee79 100644 (file)
@@ -2,7 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- * Copyright (C) 2015 - 2016 - Samuel GOUGEON
+ * 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,
  * 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="fr">
+<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="fr">
     <refnamediv>
         <refname>sign</refname>
         <refpurpose>fonction signe</refpurpose>
             <varlistentry>
                 <term>А</term>
                 <listitem>
-                    <para>matrice de nombres réels ou complexes, d'encodage dense ou creux.</para>
+                    <para>
+                        Matrice d'entiers encodés, de nombres décimaux, ou de nombres complexes.
+                        <varname>A</varname> peut être encodée creuse.
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>X</term>
                 <listitem>
-                    <para>matrice de nombres réels ou complexes.</para>
+                    <para>
+                        Matrice de taille et de type de données identiques à ceux de
+                        <varname>A</varname>.
+                    </para>
                 </listitem>
             </varlistentry>
         </variablelist>
     <refsection role="description">
         <title>Description</title>
         <para>
-            <literal>X = sign(A)</literal> renvoie la matrice contenant les signes
-            de termes <literal>A(i,j)</literal>. Pour les matrices de nombres
-            complexes, <literal>sign(A) = A./abs(A)</literal>.
+            Si <varname>X</varname> sont des entiers encodés ou des nombres décimaux,
+            <itemizedlist>
+                <listitem>
+                    <literal>X(i) = -1</literal> lorsque <literal>A(i)&lt;0</literal>
+                </listitem>
+                <listitem>
+                    <literal>X(i) = 0</literal> lorsque <literal>A(i)==0</literal>
+                </listitem>
+                <listitem>
+                    <literal>X(i) = 1</literal> lorsque <literal>A(i)>0</literal>
+                </listitem>
+                <listitem>
+                    <literal>X(i)= %nan</literal> lorsque <literal>A(i)</literal> est NaN.
+                </listitem>
+            </itemizedlist>
+        </para>
+        <para>
+            Si <varname>X</varname> est encodée en nombres complexes :
+            <literal>sign(A==0) = 0</literal>. Ailleurs, <literal>sign(A) = A./abs(A)</literal>.
         </para>
     </refsection>
     <refsection role="examples">
         <title>Exemples</title>
+        <para>Avec des nombres décimaux :</para>
         <programlisting role="example"><![CDATA[
-sign(rand(2,3))
-sign(1+%i)
+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>Avec des nombres complexes :</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>Avec une matrice creuse:</para>
+    <programlisting role="example"><![CDATA[
 sign(sprand(8,3,0.3,"normal"))
  ]]></programlisting>
     </refsection>
@@ -61,6 +129,12 @@ sign(sprand(8,3,0.3,"normal"))
             <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">
diff --git a/scilab/modules/elementary_functions/help/ja_JP/matrixoperations/sign.xml b/scilab/modules/elementary_functions/help/ja_JP/matrixoperations/sign.xml
deleted file mode 100644 (file)
index 1318081..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2008 - INRIA
- * Copyright (C) 2015 - 2016 - 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="ja">
-    <refnamediv>
-        <refname>sign</refname>
-        <refpurpose>符号関数</refpurpose>
-    </refnamediv>
-    <refsynopsisdiv>
-        <title>呼び出し手順</title>
-        <synopsis>X = sign(A)</synopsis>
-    </refsynopsisdiv>
-    <refsection role="parameters">
-        <title>引数</title>
-        <variablelist>
-            <varlistentry>
-                <term>A</term>
-                <listitem>
-                    <para>実数または複素数の行列. <varname>A</varname> may be sparse.</para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>X</term>
-                <listitem>
-                    <para>実数または複素数の行列</para>
-                </listitem>
-            </varlistentry>
-        </variablelist>
-    </refsection>
-    <refsection role="description">
-        <title>説明</title>
-        <para>
-            <literal>X = sign(A)</literal> は
-            <literal>A(i,j)</literal>の符号からなる行列を返します.
-            <literal>A</literal>が複素数の場合,
-            <literal>sign(A) = A./abs(A)</literal> 関数となります.
-        </para>
-    </refsection>
-    <refsection role="examples">
-        <title>例</title>
-        <programlisting role="example"><![CDATA[
-sign(rand(2,3))
-sign(1+%i)
-sign(sprand(8,3,0.3,"normal"))
- ]]></programlisting>
-    </refsection>
-    <refsection role="see also">
-        <title>参照</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>履歴</title>
-        <revhistory>
-            <revision>
-                <revnumber>6.0</revnumber>
-                <revdescription>Extension to sparse matrices
-                </revdescription>
-            </revision>
-        </revhistory>
-    </refsection>
-</refentry>
diff --git a/scilab/modules/elementary_functions/help/pt_BR/matrixoperations/sign.xml b/scilab/modules/elementary_functions/help/pt_BR/matrixoperations/sign.xml
deleted file mode 100644 (file)
index 82095a6..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2008 - INRIA
- * 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="pt">
-    <refnamediv>
-        <refname>sign</refname>
-        <refpurpose>função de sinal</refpurpose>
-    </refnamediv>
-    <refsynopsisdiv>
-        <title>Seqüência de Chamamento</title>
-        <synopsis>X = sign(A)</synopsis>
-    </refsynopsisdiv>
-    <refsection role="parameters">
-        <title>Parâmetros</title>
-        <variablelist>
-            <varlistentry>
-                <term>?</term>
-                <listitem>
-                    <para>real or complex matrix. <varname>A</varname> may be sparse.</para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>X</term>
-                <listitem>
-                    <para>real or complex matrix</para>
-                </listitem>
-            </varlistentry>
-        </variablelist>
-    </refsection>
-    <refsection role="description">
-        <title>Descrição</title>
-        <para>
-            <literal>X = sign(A)</literal> retorna a matriz feita dos sinais de
-            <literal>A(i,j)</literal>. Para <literal>A</literal>, feita de complexos
-            <literal>sign(A) = A./abs(A)</literal>.
-        </para>
-    </refsection>
-    <refsection role="examples">
-        <title>Exemplos</title>
-        <programlisting role="example"><![CDATA[
-sign(rand(2,3))
-sign(1+%i)
-sign(sprand(8,3,0.3,"normal"))
- ]]></programlisting>
-    </refsection>
-    <refsection role="see also">
-        <title>Ver Também</title>
-        <simplelist type="inline">
-            <member>
-                <link linkend="abs">abs</link>
-            </member>
-        </simplelist>
-    </refsection>
-    <refsection role="history">
-        <title>Histórico</title>
-        <revhistory>
-            <revision>
-                <revnumber>6.0</revnumber>
-                <revdescription>Extension to sparse matrices
-                </revdescription>
-            </revision>
-        </revhistory>
-    </refsection>
-</refentry>
index 6f1cb19..8f0075b 100644 (file)
@@ -2,6 +2,7 @@
 <!--
  * Scilab ( http://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
  *
  * 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="ru">
+<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="ru">
     <refnamediv>
         <refname>sign</refname>
-        <refpurpose>функция знака</refpurpose>
+        <refpurpose>сигнум-функция</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Синтаксис</title>
                 <term>А</term>
                 <listitem>
                     <para>
-                        вещественная или комплексная матрица. <varname>A</varname> may be sparse.
+                        матрица кодированных целых чисел, десятичных чисел или комплексных чисел.
+                        <varname>A</varname> может быть разрежённой.
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>X</term>
                 <listitem>
-                    <para>вещественная или комплексная матрица</para>
+                    <para>
+                        матрица того же размера и типа данных, что и <varname>A</varname>.
+                    </para>
                 </listitem>
             </varlistentry>
         </variablelist>
     <refsection role="description">
         <title>Описание</title>
         <para>
-            <literal>X = sign(A)</literal> возвращает матрицу, созданную из знаков
-            <literal>A(i,j)</literal>. Для комплексной  <literal>A</literal>
-            <literal>sign(A) = A./abs(A)</literal>.
+            Если <varname>X</varname> состоит из целых или вещественных чисел, то
+            <itemizedlist>
+                <listitem>
+                    <literal>X(i) = -1</literal> где <literal>A(i)&lt;0</literal>
+                </listitem>
+                <listitem>
+                    <literal>X(i) = 0</literal> где <literal>A(i)==0</literal>
+                </listitem>
+                <listitem>
+                    <literal>X(i) = 1</literal> где <literal>A(i)>0</literal>
+                </listitem>
+                <listitem>
+                    <literal>X(i)= %nan</literal> где <literal>A(i)</literal> равно NaN.
+                </listitem>
+            </itemizedlist>
+        </para>
+        <para>
+            Если <varname>X</varname> состоит из комплексных чисел: <literal>sign(A==0) = 0</literal>.
+            В противном случае <literal>sign(A) = A./abs(A)</literal>.
         </para>
     </refsection>
     <refsection role="examples">
         <title>Примеры</title>
+        <para>С десятичными числами:</para>
         <programlisting role="example"><![CDATA[
-sign(rand(2,3))
-sign(1+%i)
+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>С комплексными числами:</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>С разряжённой матрицей:</para>
+    <programlisting role="example"><![CDATA[
 sign(sprand(8,3,0.3,"normal"))
  ]]></programlisting>
     </refsection>
@@ -76,7 +139,8 @@ sign(sprand(8,3,0.3,"normal"))
         <revhistory>
             <revision>
                 <revnumber>6.0</revnumber>
-                <revdescription>Extension to sparse matrices
+                <revdescription>
+                  Расширение до разряжённых матриц.
                 </revdescription>
             </revision>
         </revhistory>
index fbdc2c7..685dc0c 100644 (file)
@@ -17,6 +17,7 @@
 #include "elem_func_gw.hxx"
 #include "function.hxx"
 #include "double.hxx"
+#include "int.hxx"
 #include "overload.hxx"
 
 extern "C"
@@ -96,6 +97,36 @@ types::Function::ReturnValue sci_sign(types::typed_list &in, int _iRetCount, typ
             out.push_back(pOut);
         }
     }
+    else if(in[0]->isInt())
+    {
+        switch (in[0]->getType())
+        {
+            case types::InternalType::ScilabInt8 :
+                out.push_back(in[0]->getAs<types::Int8>()->sign());
+                break;
+            case types::InternalType::ScilabUInt8 :
+                out.push_back(in[0]->getAs<types::UInt8>()->sign());
+                break;
+            case types::InternalType::ScilabInt16 :
+                out.push_back(in[0]->getAs<types::Int16>()->sign());
+                break;
+            case types::InternalType::ScilabUInt16 :
+                out.push_back(in[0]->getAs<types::UInt16>()->sign());
+                break;
+            case types::InternalType::ScilabInt32 :
+                out.push_back(in[0]->getAs<types::Int32>()->sign());
+                break;
+            case types::InternalType::ScilabUInt32 :
+                out.push_back(in[0]->getAs<types::UInt32>()->sign());
+                break;
+            case types::InternalType::ScilabInt64 :
+                out.push_back(in[0]->getAs<types::Int64>()->sign());
+                break;
+            case types::InternalType::ScilabUInt64 :
+                out.push_back(in[0]->getAs<types::UInt64>()->sign());
+                break;
+        }
+    }
     else
     {
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_sign";
diff --git a/scilab/modules/integer/macros/%i_sign.sci b/scilab/modules/integer/macros/%i_sign.sci
deleted file mode 100644 (file)
index 750ef86..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA -
-//
-// 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.
-
-
-function r=%i_sign(m)
-    it=inttype(m)
-    r=m;
-    r(1:$)=iconvert(1,it)
-    r(find(m<iconvert(0,it)))=iconvert(-1,it)
-endfunction
diff --git a/scilab/modules/integer/tests/nonreg_tests/bug_15535.tst b/scilab/modules/integer/tests/nonreg_tests/bug_15535.tst
new file mode 100644 (file)
index 0000000..87a8711
--- /dev/null
@@ -0,0 +1,25 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// ===========================================================================
+//
+// <-- Non-regression test for bug 15535 -->
+//
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/15535
+//
+// <-- Short Description -->
+// sign(int8(0)) returned 1 instead of 0
+
+for it = [1 2 4 8 11 12 14 18]
+    assert_checkequal(sign(iconvert(0, it)), iconvert(0,it));
+    assert_checkequal(sign(iconvert(4, it)), iconvert(1,it));
+    if it<10
+        assert_checkequal(sign(iconvert(-4, it)), iconvert(-1,it));
+    end
+end