[elementary_functions] fix argument check in log1p from < 0 to <= -1 20/17020/3
John GLIKSBERG [Tue, 11 Aug 2015 14:02:21 +0000 (16:02 +0200)]
Change-Id: I1b837a6265c1cade5158d023e1d7682605405aa3

scilab/modules/elementary_functions/sci_gateway/cpp/sci_log1p.cpp
scilab/modules/elementary_functions/tests/unit_tests/log1p.dia.ref [new file with mode: 0644]
scilab/modules/elementary_functions/tests/unit_tests/log1p.tst [new file with mode: 0644]

index 14e5e78..5adba08 100644 (file)
@@ -65,7 +65,7 @@ types::Function::ReturnValue sci_log1p(types::typed_list &in, int _iRetCount, ty
     int size = pDblIn->getSize();
     for (int i = 0; i < size; i++)
     {
-        if (pInR[i] < 0)
+        if (pInR[i] <= -1)
         {
             if (ConfigVariable::getIeee() == 0)
             {
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/log1p.dia.ref b/scilab/modules/elementary_functions/tests/unit_tests/log1p.dia.ref
new file mode 100644 (file)
index 0000000..169e52b
--- /dev/null
@@ -0,0 +1,23 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - John GLIKSBERG
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//
+//
+// <-- JVM NOT MANDATORY -->
+//
+// this corresponds to log(0.7) and should therefore be authorized.
+// it was not on some versions of Scilab
+log1p(-0.3);
+// check that log1p(x) is close to log(1+x) on a few defined values
+assert_checkalmostequal( log1p(-0.4), log(-0.4 + 1), 1e-5);
+assert_checkalmostequal( log1p(-0.0), log(-0.0 + 1), 1e-5);
+assert_checkalmostequal( log1p(+1.2), log(+1.2 + 1), 1e-5);
+assert_checkalmostequal( log1p(+5.6), log(+5.6 + 1), 1e-5);
+// this corresponds to log(0) which is and should be undefined
+assert_checkerror("log1p(-1)", "log1p: Wrong value for input argument #1 : Singularity of the function.");
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/log1p.tst b/scilab/modules/elementary_functions/tests/unit_tests/log1p.tst
new file mode 100644 (file)
index 0000000..f4b0f01
--- /dev/null
@@ -0,0 +1,26 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - John GLIKSBERG
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//
+//
+// <-- JVM NOT MANDATORY -->
+//
+
+// this corresponds to log(0.7) and should therefore be authorized.
+// it was not on some versions of Scilab
+log1p(-0.3);
+
+// check that log1p(x) is close to log(1+x) on a few defined values
+assert_checkalmostequal( log1p(-0.4), log(-0.4 + 1), 1e-5);
+assert_checkalmostequal( log1p(-0.0), log(-0.0 + 1), 1e-5);
+assert_checkalmostequal( log1p(+1.2), log(+1.2 + 1), 1e-5);
+assert_checkalmostequal( log1p(+5.6), log(+5.6 + 1), 1e-5);
+
+// this corresponds to log(0) which is and should be undefined
+assert_checkerror("log1p(-1)", "log1p: Wrong value for input argument #1 : Singularity of the function.");