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

Eike Rathke erack at redhat.com
Sat Oct 24 19:35:17 UTC 2015


 sal/qa/rtl/math/test-rtl-math.cxx |   34 ++++++++++++++++++++++++++++++++++
 sal/rtl/math.cxx                  |   22 ++++++++++++++++++++++
 2 files changed, 56 insertions(+)

New commits:
commit 9846b6ab3d36c8b2696e8829c121016f9fa81e66
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Oct 24 21:31:45 2015 +0200

    unit tests for rtl_math_erf() and rtl_math_erfc()
    
    Change-Id: Ia6b025ba9980f0a7b333b2dc4ae708c3a63fca21

diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx
index e6422c4..b462de4 100644
--- a/sal/qa/rtl/math/test-rtl-math.cxx
+++ b/sal/qa/rtl/math/test-rtl-math.cxx
@@ -88,10 +88,44 @@ public:
         CPPUNIT_ASSERT_EQUAL(0.0, res);
     }
 
+    void test_erf() {
+        double x, res;
+        x =  0.0;
+        res = rtl::math::erf(x);
+        CPPUNIT_ASSERT_EQUAL(0.0,res);
+        rtl::math::setInf( &x, false);
+        res = rtl::math::erf(x);
+        CPPUNIT_ASSERT_EQUAL(1.0,res);
+        rtl::math::setInf( &x, true);
+        res = rtl::math::erf(x);
+        CPPUNIT_ASSERT_EQUAL(-1.0,res);
+        rtl::math::setNan( &x);
+        res = rtl::math::erf(x);
+        CPPUNIT_ASSERT_EQUAL(true,rtl::math::isNan(x));
+    }
+
+    void test_erfc() {
+        double x, res;
+        x =  0.0;
+        res = rtl::math::erfc(x);
+        CPPUNIT_ASSERT_EQUAL(1.0,res);
+        rtl::math::setInf( &x, false);
+        res = rtl::math::erfc(x);
+        CPPUNIT_ASSERT_EQUAL(0.0,res);
+        rtl::math::setInf( &x, true);
+        res = rtl::math::erfc(x);
+        CPPUNIT_ASSERT_EQUAL(2.0,res);
+        rtl::math::setNan( &x);
+        res = rtl::math::erfc(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_SUITE_END();
 };
 
commit 5f2db274dbf4d8b808f9ddbe4959deadbc1ec9fa
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Oct 24 21:30:14 2015 +0200

    implement proper Inf and NaN handling in rtl_math_erf() and rtl_math_erfc()
    
    Change-Id: Ib96d7123a3c483e9a1c78666bf042396510d733f

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 9599028..37225f4 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -1143,7 +1143,18 @@ double SAL_CALL rtl_math_erf( double x ) SAL_THROW_EXTERN_C()
 
     // Otherwise we may end up in endless recursion through rtl_math_erfc().
     if (!::rtl::math::isFinite(x))
+    {
+        // See http://en.cppreference.com/w/cpp/numeric/math/erf
+        if (::rtl::math::isInf(x))
+        {
+            if (::rtl::math::isSignBitSet(x))
+                return -1.0;
+            else
+                return 1.0;
+        }
+        // It is a NaN.
         return x;
+    }
 
     bool bNegative = false;
     if ( x < 0.0 )
@@ -1183,7 +1194,18 @@ double SAL_CALL rtl_math_erfc( double x ) SAL_THROW_EXTERN_C()
 
     // Otherwise we may end up in endless recursion through rtl_math_erf().
     if (!::rtl::math::isFinite(x))
+    {
+        // See http://en.cppreference.com/w/cpp/numeric/math/erfc
+        if (::rtl::math::isInf(x))
+        {
+            if (::rtl::math::isSignBitSet(x))
+                return 2.0;
+            else
+                return 0.0;
+        }
+        // It is a NaN.
         return x;
+    }
 
     bool bNegative = false;
     if ( x < 0.0 )


More information about the Libreoffice-commits mailing list