[Libreoffice-commits] core.git: 2 commits - sal/qa sal/rtl

Eike Rathke erack at redhat.com
Sat Oct 24 20:08:26 UTC 2015


 sal/qa/rtl/math/test-rtl-math.cxx |   48 ++++++++++++++++++++++++++++++++++++++
 sal/rtl/math.cxx                  |   43 ++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

New commits:
commit 34abbb53f347f53892cc9dde60e36499588681fd
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Oct 24 22:05:36 2015 +0200

    unit tests for rtl_math_expm1() and rtl_math_log1p()
    
    Change-Id: I1b573365d55f6455e892b4b5b98a7090de5caf4c

diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx
index b462de4..1d3f07f 100644
--- a/sal/qa/rtl/math/test-rtl-math.cxx
+++ b/sal/qa/rtl/math/test-rtl-math.cxx
@@ -120,12 +120,60 @@ public:
         CPPUNIT_ASSERT_EQUAL(true,rtl::math::isNan(x));
     }
 
+    void test_expm1() {
+        double x, res;
+        x =  0.0;
+        res = rtl::math::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(0.0,res);
+        x = -0.0;
+        res = rtl::math::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(-0.0,res);
+        CPPUNIT_ASSERT_EQUAL(true, rtl::math::isSignBitSet(res));
+        rtl::math::setInf( &x, false);
+        res = rtl::math::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(true, rtl::math::isInf(res) && !rtl::math::isSignBitSet(res));
+        rtl::math::setInf( &x, true);
+        res = rtl::math::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(-1.0,res);
+        rtl::math::setNan( &x);
+        res = rtl::math::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(true,rtl::math::isNan(x));
+    }
+
+    void test_log1p() {
+        double x, res;
+        x =  0.0;
+        res = rtl::math::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(0.0,res);
+        x = -0.0;
+        res = rtl::math::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(-0.0,res);
+        CPPUNIT_ASSERT_EQUAL(true, rtl::math::isSignBitSet(res));
+        rtl::math::setInf( &x, false);
+        res = rtl::math::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(true, rtl::math::isInf(res) && !rtl::math::isSignBitSet(res));
+        x = -1.0;
+        res = rtl::math::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(true, rtl::math::isInf(res) && rtl::math::isSignBitSet(res));
+        x = -1.1;
+        res = rtl::math::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(true, rtl::math::isNan(res));
+        rtl::math::setInf( &x, true);
+        res = rtl::math::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(true, rtl::math::isNan(res));
+        rtl::math::setNan( &x);
+        res = rtl::math::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(true,rtl::math::isNan(x));
+    }
+
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(test_stringToDouble_good);
     CPPUNIT_TEST(test_stringToDouble_bad);
     CPPUNIT_TEST(test_stringToDouble_exponent_without_digit);
     CPPUNIT_TEST(test_erf);
     CPPUNIT_TEST(test_erfc);
+    CPPUNIT_TEST(test_expm1);
+    CPPUNIT_TEST(test_log1p);
     CPPUNIT_TEST_SUITE_END();
 };
 
commit 04967cba8e71e178915068e237a96e32a8cb3e9e
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Oct 24 22:04:28 2015 +0200

    implement Inf and NaN handling for rtl_math_expm1() and rtl_math_log1p()
    
    Change-Id: Ie424a6f038107ef8b574d0422efaf49b441c110f

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 37225f4..3ec6fe0 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -1096,6 +1096,24 @@ double SAL_CALL rtl_math_approxValue( double fValue ) SAL_THROW_EXTERN_C()
 
 double SAL_CALL rtl_math_expm1( double fValue ) SAL_THROW_EXTERN_C()
 {
+    // See http://en.cppreference.com/w/cpp/numeric/math/expm1
+
+    if (fValue == 0.0)
+        return fValue;
+
+    if (!::rtl::math::isFinite(fValue))
+    {
+        if (::rtl::math::isInf(fValue))
+        {
+            if (::rtl::math::isSignBitSet(fValue))
+                return -1.0;
+            else
+                return fValue;
+        }
+        // It is a NaN.
+        return fValue;
+    }
+
     double fe = exp( fValue );
     if (fe == 1.0)
         return fValue;
@@ -1106,6 +1124,31 @@ double SAL_CALL rtl_math_expm1( double fValue ) SAL_THROW_EXTERN_C()
 
 double SAL_CALL rtl_math_log1p( double fValue ) SAL_THROW_EXTERN_C()
 {
+    // See http://en.cppreference.com/w/cpp/numeric/math/log1p
+
+    if (fValue == 0.0)
+        return fValue;
+
+    if (fValue == -1.0)
+    {
+        rtl::math::setInf( &fValue, true);
+        return fValue;
+    }
+
+    if (fValue < -1.0)  // includes -Inf
+    {
+        rtl::math::setNan( &fValue);
+        return fValue;
+    }
+
+    if (!::rtl::math::isFinite(fValue))
+    {
+        if (::rtl::math::isInf(fValue))
+            return fValue;
+        // It is a NaN.
+        return fValue;
+    }
+
     // Use volatile because a compiler may be too smart "optimizing" the
     // condition such that in certain cases the else path was called even if
     // (fp==1.0) was true, where the term (fp-1.0) then resulted in 0.0 and


More information about the Libreoffice-commits mailing list