From 08381f7465099d730e7329e211e03633f971ac7e Mon Sep 17 00:00:00 2001
From: John GLIKSBERG
Date: Tue, 11 Aug 2015 16:02:21 +0200
Subject: [PATCH] [elementary_functions] fix argument check in log1p from < 0
to <= -1
Change-Id: I1b837a6265c1cade5158d023e1d7682605405aa3
---
.../sci_gateway/cpp/sci_log1p.cpp | 2 +-
.../tests/unit_tests/log1p.dia.ref | 23 +++++++++++++++++
.../tests/unit_tests/log1p.tst | 26 ++++++++++++++++++++
3 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 scilab/modules/elementary_functions/tests/unit_tests/log1p.dia.ref
create mode 100644 scilab/modules/elementary_functions/tests/unit_tests/log1p.tst
diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_log1p.cpp b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_log1p.cpp
index 14e5e78..5adba08 100644
--- a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_log1p.cpp
+++ b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_log1p.cpp
@@ -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
index 0000000..169e52b
--- /dev/null
+++ b/scilab/modules/elementary_functions/tests/unit_tests/log1p.dia.ref
@@ -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
index 0000000..f4b0f01
--- /dev/null
+++ b/scilab/modules/elementary_functions/tests/unit_tests/log1p.tst
@@ -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.");
--
1.7.9.5