* Bug 15599 fixed: now degree of zero polynomial is -Inf 91/20091/4
Stéphane Mottelet [Thu, 31 May 2018 16:41:03 +0000 (18:41 +0200)]
http://bugzilla.scilab.org/show_bug.cgi?id=15599

Change-Id: Ife13ef1302cc5b825555f078cdc591a2de11c54e

scilab/CHANGES.md
scilab/modules/ast/includes/types/singlepoly.hxx
scilab/modules/ast/src/cpp/types/singlepoly.cpp
scilab/modules/polynomials/help/en_US/degree.xml
scilab/modules/polynomials/help/fr_FR/degree.xml
scilab/modules/polynomials/help/ja_JP/degree.xml
scilab/modules/polynomials/help/pt_BR/degree.xml
scilab/modules/polynomials/sci_gateway/cpp/sci_degree.cpp
scilab/modules/polynomials/tests/nonreg_tests/bug_15599.tst [new file with mode: 0644]

index 7872657..0adf739 100644 (file)
@@ -439,6 +439,7 @@ Known issues
 * [#15551](http://bugzilla.scilab.org/show_bug.cgi?id=15551): arithmetic operators gave wrong results with booleans.
 * [#15563](http://bugzilla.scilab.org/show_bug.cgi?id=15563): poly(A,v) was broken when A is a matrix.
 * [#15566](http://bugzilla.scilab.org/show_bug.cgi?id=15566): matrix insertion checked overall size but not individual dimensions.
+* [#15599](http://bugzilla.scilab.org/show_bug.cgi?id=15599): degree of zero polynomial was 0 instead of -Inf.
 
 
 
index e88b6a9..226d356 100644 (file)
@@ -52,6 +52,7 @@ public :
 
     bool                    setZeros();
     int                     getRank();
+    double                  getDegree();
     bool                    setRank(int _iRank, bool bSave = false);
     bool                    setCoef(Double *_poPow);
     bool                    setCoef(const double *_pdblCoefR, const double *_pdblCoefI);
index 11d0e32..9e33a42 100644 (file)
@@ -134,6 +134,11 @@ int SinglePoly::getRank()
     return m_iSize - 1;
 }
 
+double SinglePoly::getDegree()
+{
+    return m_iSize==1 && m_pRealData[0]==0 && (m_pImgData == NULL || m_pImgData[0]==0) ? -INFINITY : m_iSize - 1;
+}
+
 bool SinglePoly::setRank(int _iRank, bool bSave)
 {
     double *pR = NULL;
index 28d45be..5ba01e5 100644 (file)
@@ -20,7 +20,7 @@
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>[D]=degree(M)</synopsis>
+        <synopsis>D = degree(M)</synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
@@ -71,4 +71,15 @@ degree(p) // should return 42
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    For any null polynomial, degree() now returns -%inf instead of 0.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 0040c43..a15a8d1 100644 (file)
@@ -6,7 +6,7 @@
     </refnamediv>
     <refsynopsisdiv>
         <title>Séquence d'appel</title>
-        <synopsis>[D]=degree(M)</synopsis>
+        <synopsis>D = degree(M)</synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Paramètres</title>
@@ -59,4 +59,15 @@ degree(p) // Devrait retourner 42
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Historique</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    Pour tout polynôme nul, degree() produit désormais -%inf au lieu de 0.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index fbe2b37..d6670ba 100644 (file)
@@ -20,7 +20,7 @@
     </refnamediv>
     <refsynopsisdiv>
         <title>呼び出し手順</title>
-        <synopsis>[D]=degree(M)</synopsis>
+        <synopsis>D = degree(M)</synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>パラメータ</title>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>履歴</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    nullの多項式の場合、degree()は0の代わりに - %infを返すようになりました.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 7e46fcd..a710472 100644 (file)
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="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="degree" xml:lang="pt">
     <refnamediv>
         <refname>degree</refname>
-        <refpurpose>grau da matriz de polinômios</refpurpose>
+        <refpurpose>grau da matriz de polinômios</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
-        <title> Seqüência de Chamamento </title>
-        <synopsis>[D]=degree(M)</synopsis>
+        <title> Seqüência de Chamamento </title>
+        <synopsis>D = degree(M)</synopsis>
     </refsynopsisdiv>
     <refsection>
-        <title>Parâmetros</title>
+        <title>Parâmetros</title>
         <variablelist>
             <varlistentry>
                 <term>M</term>
                 <listitem>
-                    <para>matriz de polinômios </para>
+                    <para>matriz de polinômios </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
         </variablelist>
     </refsection>
     <refsection>
-        <title>Descrição</title>
+        <title>Descrição</title>
         <para>Retorna a matriz de graus mais elevados de
             <literal>M</literal>.
         </para>
     </refsection>
     <refsection>
-        <title> Ver Também </title>
+        <title> Ver Também </title>
         <simplelist type="inline">
             <member>
                 <link linkend="poly">poly</link>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Histórico</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    Para qualquer polinômio nulo, degree() agora retorna -%inf em vez de 0.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 5a4fb0d..4c26c74 100644 (file)
@@ -45,9 +45,24 @@ types::Function::ReturnValue sci_degree(types::typed_list &in, int _iRetCount, t
     if (in[0]->isDouble())
     {
         types::Double* pDblIn = in[0]->getAs<types::Double>();
+        double *pReal = pDblIn->get();
         pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray());
         double* pdblOut = pDblOut->get();
-        memset(pdblOut, 0x00, pDblOut->getSize() * sizeof(double));
+        if (pDblIn->isComplex())
+        {
+            double *pImg = pDblIn->getImg();
+            for (int i = 0; i < pDblOut->getSize(); i++)
+            {
+                pdblOut[i] = pReal[i]==0 && pImg[i]==0 ? -INFINITY : 0;;
+            }
+        }
+        else
+        {
+            for (int i = 0; i < pDblOut->getSize(); i++)
+            {
+                pdblOut[i] = pReal[i]==0 ? -INFINITY : 0;
+            }
+        }
     }
     else if (in[0]->isPoly())
     {
@@ -57,7 +72,7 @@ types::Function::ReturnValue sci_degree(types::typed_list &in, int _iRetCount, t
 
         for (int i = 0; i < pDblOut->getSize(); i++)
         {
-            pdblOut[i] = (double)pPolyIn->get(i)->getRank();
+            pdblOut[i] = pPolyIn->get(i)->getDegree();
         }
     }
     else
diff --git a/scilab/modules/polynomials/tests/nonreg_tests/bug_15599.tst b/scilab/modules/polynomials/tests/nonreg_tests/bug_15599.tst
new file mode 100644 (file)
index 0000000..a6d5498
--- /dev/null
@@ -0,0 +1,25 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - Stéphane Mottelet
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+//
+// <-- Non-regression test for bug 15599 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/15599
+//
+// <-- Short Description -->
+// degree of zero polynomial should be -Inf instead of 0
+
+p=poly(0,'x','coeff');
+q=poly(1,'x','coeff');
+assert_checkequal(degree(p),-%inf);
+assert_checkequal(degree([p q q-q 0*%s 0*%i*%s]),[-%inf 0 -%inf -%inf -%inf]);
+assert_checkequal(degree(0),-%inf);
+assert_checkequal(degree([0 0*%i 1]),[-%inf -%inf 0]);
+assert_checkequal(degree([%nan %nan+%s %nan+0*%s]),[0 1 0]);