* Bug 14746 fixed: display of tiny numbers is repaired 91/21091/2
Stéphane MOTTELET [Wed, 18 Sep 2019 14:21:11 +0000 (16:21 +0200)]
http://bugzilla.scilab.org/show_bug.cgi?id=14746

Change-Id: I5b65fc8401509505e6146308fda991ef7127746b

scilab/CHANGES.md
scilab/modules/ast/src/cpp/types/double.cpp
scilab/modules/ast/src/cpp/types/tostring_common.cpp
scilab/modules/ast/tests/nonreg_tests/bug_14746.dia.ref [new file with mode: 0644]
scilab/modules/ast/tests/nonreg_tests/bug_14746.tst [new file with mode: 0644]

index 2372012..df7149a 100644 (file)
@@ -186,6 +186,7 @@ Bug Fixes
 * [#14605](http://bugzilla.scilab.org/show_bug.cgi?id=14605): fixed - `bench_run` was too strict about the specification of tests names.
 * [#14606](http://bugzilla.scilab.org/show_bug.cgi?id=14606): Memory used by variables returned by `[names,mem]=who()` was always zero.
 * [#14741](http://bugzilla.scilab.org/show_bug.cgi?id=14741): The syntax `[m,e]=log2(x)` was not documented. As public function `frexp()` was in duplicate with `[m,e]=log2(x)`.
+* [#14746](http://bugzilla.scilab.org/show_bug.cgi?id=14746): Tiny numbers were sometimes displayed as 0.
 * [#14791](http://bugzilla.scilab.org/show_bug.cgi?id=14791): `sleep 1` crashed Scilab.
 * [#14812](http://bugzilla.scilab.org/show_bug.cgi?id=14812): Minor typos in messages.
 * [#14863](http://bugzilla.scilab.org/show_bug.cgi?id=14863): In Xcos, the default ending time was unhandily high (100000), reduced it to 30.
index aa38282..761f8c7 100644 (file)
@@ -418,7 +418,7 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                     int iPos = getIndex(_piDims);
 
                     DoubleFormat df;
-                    getDoubleFormat(ZeroIsZero(m_pRealData[iPos]), &df);
+                    getDoubleFormat(m_pRealData[iPos], &df);
                     piSize[iCols1] = std::max(piSize[iCols1], df.iWidth);
                 }
             }
@@ -453,12 +453,12 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                             int iPos = getIndex(_piDims);
 
                             DoubleFormat df;
-                            getDoubleFormat(ZeroIsZero(m_pRealData[iPos]), &df);
+                            getDoubleFormat(m_pRealData[iPos], &df);
 
                             ostemp << SPACE_BETWEEN_TWO_VALUES;
 
                             df.iWidth = piSize[iCols2];
-                            addDoubleValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), &df);
+                            addDoubleValue(&ostemp, m_pRealData[iPos], &df);
                         }
                         ostemp << std::endl;
                     }
@@ -505,11 +505,11 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                     int iPos = getIndex(_piDims);
 
                     DoubleFormat df;
-                    getDoubleFormat(ZeroIsZero(m_pRealData[iPos]), &df);
+                    getDoubleFormat(m_pRealData[iPos], &df);
 
                     ostemp << SPACE_BETWEEN_TWO_VALUES;
                     df.iWidth = piSize[iCols2];
-                    addDoubleValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), &df);
+                    addDoubleValue(&ostemp, m_pRealData[iPos], &df);
                 }
                 ostemp << std::endl;
             }
@@ -533,7 +533,7 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                     int iPos = getIndex(_piDims);
 
                     DoubleFormat dfR, dfI;
-                    getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI);
+                    getComplexFormat(m_pRealData[iPos], m_pImgData[iPos], &iTotalWidth, &dfR, &dfI);
                     // keep track of real and imaginary part width for further alignment
                     piISize[iCols1] = std::max(piISize[iCols1], dfI.iWidth);
                     piRSize[iCols1] = std::max(piRSize[iCols1], dfR.iWidth);
@@ -572,13 +572,13 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                             int iPos = getIndex(_piDims);
 
                             DoubleFormat dfR, dfI;
-                            getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI);
+                            getComplexFormat(m_pRealData[iPos], m_pImgData[iPos], &iTotalWidth, &dfR, &dfI);
 
                             // override with precomputed real part width for alignment of imaginary part sign
                             dfR.iWidth = piRSize[iCols2];
                             dfI.iWidth = piISize[iCols2];
                             ostemp << SPACE_BETWEEN_TWO_VALUES;
-                            addDoubleComplexValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]),  piSize[iCols2], &dfR, &dfI);
+                            addDoubleComplexValue(&ostemp, m_pRealData[iPos], m_pImgData[iPos],  piSize[iCols2], &dfR, &dfI);
                         }
                         ostemp << std::endl;
                     }
@@ -626,13 +626,13 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                     int iPos = getIndex(_piDims);
 
                     DoubleFormat dfR, dfI;
-                    getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI);
+                    getComplexFormat(m_pRealData[iPos], m_pImgData[iPos], &iTotalWidth, &dfR, &dfI);
 
                     // override with precomputed real part width for aligment of imaginary part sign
                     dfR.iWidth = piRSize[iCols2];
                     dfI.iWidth = piISize[iCols2];
                     ostemp << SPACE_BETWEEN_TWO_VALUES;
-                    addDoubleComplexValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]),  piSize[iCols2], &dfR, &dfI);
+                    addDoubleComplexValue(&ostemp, m_pRealData[iPos], m_pImgData[iPos],  piSize[iCols2], &dfR, &dfI);
                 }
                 ostemp << std::endl;
             }
index e1a222e..0df8d0c 100644 (file)
@@ -433,7 +433,7 @@ void printComplexValue(std::wostringstream& ostr, double val_r, double val_i)
     dfI.bPrintTrailingZeros = true;
 
     int iTotalWidth;
-    getComplexFormat(ZeroIsZero(val_r), ZeroIsZero(val_i), &iTotalWidth, &dfR, &dfI);
+    getComplexFormat(val_r, val_i, &iTotalWidth, &dfR, &dfI);
     ostr << SPACE_BETWEEN_TWO_VALUES;
-    addDoubleComplexValue(&ostr, ZeroIsZero(val_r), ZeroIsZero(val_i), iTotalWidth, &dfR, &dfI);
+    addDoubleComplexValue(&ostr, val_r, val_i, iTotalWidth, &dfR, &dfI);
 }
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_14746.dia.ref b/scilab/modules/ast/tests/nonreg_tests/bug_14746.dia.ref
new file mode 100644 (file)
index 0000000..f4ffe62
--- /dev/null
@@ -0,0 +1,31 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2019 - Stéphane MOTTELET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 14746 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/14746
+//
+// <-- Short Description -->
+// The display of tiny complex numbers displays 0
+format("v")
+disp([1, %eps/2])
+   1.   1.110D-16
+assert_checkequal(string([1, %eps/2]) , ["1","1.110D-16"]);
+format("e")
+disp([1, %eps/2])
+   1.000D+00   1.110D-16
+assert_checkequal(string([1, %eps/2]) , ["1.000D+00","1.110D-16"]);
+format("v")
+disp(complex(%eps/2,0))
+   1.110D-16 + 0.i
+assert_checkequal(string(complex(%eps/2,0)) , "1.110D-16");
+format("e")
+disp(complex(%eps/2,0))
+   1.110D-16 + 0.000D+00i
+assert_checkequal(string(complex(%eps/2,0)) , "1.110D-16");
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_14746.tst b/scilab/modules/ast/tests/nonreg_tests/bug_14746.tst
new file mode 100644 (file)
index 0000000..94c8436
--- /dev/null
@@ -0,0 +1,32 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2019 - Stéphane MOTTELET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 14746 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/14746
+//
+// <-- Short Description -->
+// The display of tiny complex numbers displays 0
+
+format("v")
+disp([1, %eps/2])
+assert_checkequal(string([1, %eps/2]) , ["1","1.110D-16"]);
+
+format("e")
+disp([1, %eps/2])
+assert_checkequal(string([1, %eps/2]) , ["1.000D+00","1.110D-16"]);
+
+format("v")
+disp(complex(%eps/2,0))
+assert_checkequal(string(complex(%eps/2,0)) , "1.110D-16");
+
+format("e")
+disp(complex(%eps/2,0))
+assert_checkequal(string(complex(%eps/2,0)) , "1.110D-16");
+