sal/CppunitTest_sal_rtl.mk        |    1 
 sal/qa/rtl/math/test-rtl-math.cxx |   58 +++++------
 sal/qa/rtl/math/test-std-math.cxx |  195 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 225 insertions(+), 29 deletions(-)

New commits:
commit e3d120e2ba991897bf7d8eff6cc4eba00f7d749e
Author:     Liu Hao <ianahao...@gmail.com>
AuthorDate: Mon Aug 22 23:32:00 2022 +0800
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Tue Aug 23 08:44:48 2022 +0200

    tdf#148430 Use std math functions instead of rtl::math
    
    Revert the changes in rtl unit tests.
    Add some new unit tests to demonstrate the behavior of std
    functions is same as rtl functions.
    
    Change-Id: I12603e2502b8d0951ff5e1650dc8fa193d67c856
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138696
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/sal/CppunitTest_sal_rtl.mk b/sal/CppunitTest_sal_rtl.mk
index 2568d8dde70c..c0291914c830 100644
--- a/sal/CppunitTest_sal_rtl.mk
+++ b/sal/CppunitTest_sal_rtl.mk
@@ -20,6 +20,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl,\
        sal/qa/rtl/doublelock/rtl_doublelocking \
        sal/qa/rtl/locale/rtl_locale \
        sal/qa/rtl/math/test-rtl-math \
+       sal/qa/rtl/math/test-std-math \
        sal/qa/rtl/ostring/rtl_str \
        sal/qa/rtl/oustring/rtl_ustr \
        sal/qa/rtl/oustringbuffer/test_oustringbuffer_appendchar \
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx 
b/sal/qa/rtl/math/test-rtl-math.cxx
index 69a54bd814ef..ee4ae55a1a4b 100644
--- a/sal/qa/rtl/math/test-rtl-math.cxx
+++ b/sal/qa/rtl/math/test-rtl-math.cxx
@@ -505,84 +505,84 @@ public:
     void test_erf() {
         double x, res;
         x =  0.0;
-        res = std::erf(x);
+        res = rtl::math::erf(x);
         CPPUNIT_ASSERT_EQUAL(0.0,res);
         rtl::math::setInf( &x, false);
-        res = std::erf(x);
+        res = rtl::math::erf(x);
         CPPUNIT_ASSERT_EQUAL(1.0,res);
         rtl::math::setInf( &x, true);
-        res = std::erf(x);
+        res = rtl::math::erf(x);
         CPPUNIT_ASSERT_EQUAL(-1.0,res);
         rtl::math::setNan( &x);
-        res = std::erf(x);
+        res = rtl::math::erf(x);
         CPPUNIT_ASSERT(std::isnan(res));
         x = 3.0;
-        res = std::erf(-x);
-        CPPUNIT_ASSERT_DOUBLES_EQUAL( -std::erf(x), res, 1E-12);
+        res = rtl::math::erf(-x);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL( -rtl::math::erf(x), res, 1E-12);
     }
 
     void test_erfc() {
         double x, res;
         x =  0.0;
-        res = std::erfc(x);
+        res = rtl::math::erfc(x);
         CPPUNIT_ASSERT_EQUAL(1.0,res);
         rtl::math::setInf( &x, false);
-        res = std::erfc(x);
+        res = rtl::math::erfc(x);
         CPPUNIT_ASSERT_EQUAL(0.0,res);
         rtl::math::setInf( &x, true);
-        res = std::erfc(x);
+        res = rtl::math::erfc(x);
         CPPUNIT_ASSERT_EQUAL(2.0,res);
         rtl::math::setNan( &x);
-        res = std::erfc(x);
+        res = rtl::math::erfc(x);
         CPPUNIT_ASSERT(std::isnan(res));
         x = 3.0;
-        res = std::erfc(-x);
-        CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0 - std::erfc(x), res, 1E-12);
+        res = rtl::math::erfc(-x);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0 - rtl::math::erfc(x), res, 1E-12);
     }
 
     void test_expm1() {
         double x, res;
         x =  0.0;
-        res = std::expm1(x);
+        res = rtl::math::expm1(x);
         CPPUNIT_ASSERT_EQUAL(0.0,res);
         x = -0.0;
-        res = std::expm1(x);
+        res = rtl::math::expm1(x);
         CPPUNIT_ASSERT_EQUAL(-0.0,res);
         CPPUNIT_ASSERT(std::signbit(res));
         rtl::math::setInf( &x, false);
-        res = std::expm1(x);
+        res = rtl::math::expm1(x);
         CPPUNIT_ASSERT_EQUAL(true, std::isinf(res) && !std::signbit(res));
         rtl::math::setInf( &x, true);
-        res = std::expm1(x);
+        res = rtl::math::expm1(x);
         CPPUNIT_ASSERT_EQUAL(-1.0,res);
         rtl::math::setNan( &x);
-        res = std::expm1(x);
+        res = rtl::math::expm1(x);
         CPPUNIT_ASSERT(std::isnan(res));
     }
 
     void test_log1p() {
         double x, res;
         x =  0.0;
-        res = std::log1p(x);
+        res = rtl::math::log1p(x);
         CPPUNIT_ASSERT_EQUAL(0.0,res);
         x = -0.0;
-        res = std::log1p(x);
+        res = rtl::math::log1p(x);
         CPPUNIT_ASSERT_EQUAL(-0.0,res);
         CPPUNIT_ASSERT(std::signbit(res));
         rtl::math::setInf( &x, false);
-        res = std::log1p(x);
+        res = rtl::math::log1p(x);
         CPPUNIT_ASSERT_EQUAL(true, std::isinf(res) && !std::signbit(res));
         x = -1.0;
-        res = std::log1p(x);
+        res = rtl::math::log1p(x);
         CPPUNIT_ASSERT_EQUAL(true, std::isinf(res) && std::signbit(res));
         x = -1.1;
-        res = std::log1p(x);
+        res = rtl::math::log1p(x);
         CPPUNIT_ASSERT(std::isnan(res));
         rtl::math::setInf( &x, true);
-        res = std::log1p(x);
+        res = rtl::math::log1p(x);
         CPPUNIT_ASSERT(std::isnan(res));
         rtl::math::setNan( &x);
-        res = std::log1p(x);
+        res = rtl::math::log1p(x);
         CPPUNIT_ASSERT(std::isnan(res));
     }
 
@@ -636,20 +636,20 @@ public:
     void test_atanh() {
         double res;
 
-        res = std::atanh(-2.0); // NaN
+        res = rtl::math::atanh(-2.0); // NaN
         CPPUNIT_ASSERT(std::isnan(res));
 
-        res = std::atanh(-1.0); // -Inf
+        res = rtl::math::atanh(-1.0); // -Inf
         CPPUNIT_ASSERT(std::signbit(res));
         CPPUNIT_ASSERT(std::isinf(res));
 
-        CPPUNIT_ASSERT_EQUAL(0.0, std::atanh(0.0));
+        CPPUNIT_ASSERT_EQUAL(0.0, rtl::math::atanh(0.0));
 
-        res = std::atanh(1.0); // +Inf
+        res = rtl::math::atanh(1.0); // +Inf
         CPPUNIT_ASSERT(!std::signbit(res));
         CPPUNIT_ASSERT(std::isinf(res));
 
-        res = std::atanh(2.0); // NaN
+        res = rtl::math::atanh(2.0); // NaN
         CPPUNIT_ASSERT(std::isnan(res));
     }
 
diff --git a/sal/qa/rtl/math/test-std-math.cxx 
b/sal/qa/rtl/math/test-std-math.cxx
new file mode 100644
index 000000000000..214e1c792dbe
--- /dev/null
+++ b/sal/qa/rtl/math/test-std-math.cxx
@@ -0,0 +1,195 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/types.h>
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <rtl/math.hxx>
+#include <rtl/ustring.h>
+#include <rtl/ustring.hxx>
+#include <limits>
+#include <cmath>
+
+/*
+In tdf#148430, we try to replace rtl math functions to std functions,
+this unit test is to demonstrate this replacement will not change
+the behavior of code and no other unexpected results.
+
+You can see more discussions in https://gerrit.libreoffice.org/c/core/+/138294.
+*/
+
+class Test : public CppUnit::TestFixture
+{
+public:
+    void test_erf()
+    {
+        double x, rtl_res, std_res;
+        x = 0.0;
+        rtl_res = rtl::math::erf(x);
+        std_res = std::erf(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        rtl::math::setInf(&x, false);
+        rtl_res = rtl::math::erf(x);
+        std_res = std::erf(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        rtl::math::setInf(&x, true);
+        rtl_res = rtl::math::erf(x);
+        std_res = std::erf(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        rtl::math::setNan(&x);
+        rtl_res = rtl::math::erf(x);
+        std_res = std::erf(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+        x = 3.0;
+        rtl_res = rtl::math::erf(-x);
+        std_res = std::erf(-x);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(-std::erf(x), rtl_res, 1E-12);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(-rtl::math::erf(x), std_res, 1E-12);
+    }
+
+    void test_erfc()
+    {
+        double x, rtl_res, std_res;
+        x = 0.0;
+        rtl_res = rtl::math::erfc(x);
+        std_res = std::erfc(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        rtl::math::setInf(&x, false);
+        rtl_res = rtl::math::erfc(x);
+        std_res = std::erfc(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        rtl::math::setInf(&x, true);
+        rtl_res = rtl::math::erfc(x);
+        std_res = std::erfc(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        rtl::math::setNan(&x);
+        rtl_res = rtl::math::erfc(x);
+        std_res = std::erfc(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+        x = 3.0;
+        rtl_res = rtl::math::erfc(-x);
+        std_res = std::erfc(-x);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0 - std::erfc(x), rtl_res, 1E-12);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0 - rtl::math::erfc(x), std_res, 1E-12);
+    }
+
+    void test_expm1()
+    {
+        double x, rtl_res, std_res;
+        x = 0.0;
+        rtl_res = rtl::math::expm1(x);
+        std_res = std::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        x = -0.0;
+        rtl_res = rtl::math::expm1(x);
+        std_res = std::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        CPPUNIT_ASSERT_EQUAL(std::signbit(rtl_res), std::signbit(std_res));
+        rtl::math::setInf(&x, false);
+        rtl_res = rtl::math::expm1(x);
+        std_res = std::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(std::isinf(rtl_res) && !std::signbit(rtl_res),
+                             std::isinf(std_res) && !std::signbit(std_res));
+        rtl::math::setInf(&x, true);
+        rtl_res = rtl::math::expm1(x);
+        std_res = std::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        rtl::math::setNan(&x);
+        rtl_res = rtl::math::expm1(x);
+        std_res = std::expm1(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+    }
+
+    void test_log1p()
+    {
+        double x, rtl_res, std_res;
+        x = 0.0;
+        rtl_res = rtl::math::log1p(x);
+        std_res = std::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        x = -0.0;
+        rtl_res = rtl::math::log1p(x);
+        std_res = std::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        CPPUNIT_ASSERT_EQUAL(std::signbit(rtl_res), std::signbit(std_res));
+        rtl::math::setInf(&x, false);
+        rtl_res = rtl::math::log1p(x);
+        std_res = std::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(std::isinf(rtl_res) && !std::signbit(rtl_res),
+                             std::isinf(std_res) && !std::signbit(std_res));
+        x = -1.0;
+        rtl_res = rtl::math::log1p(x);
+        std_res = std::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(std::isinf(rtl_res) && std::signbit(rtl_res),
+                             std::isinf(std_res) && std::signbit(std_res));
+        x = -1.1;
+        rtl_res = rtl::math::log1p(x);
+        std_res = std::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+        rtl::math::setInf(&x, true);
+        rtl_res = rtl::math::log1p(x);
+        std_res = std::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+        rtl::math::setNan(&x);
+        rtl_res = rtl::math::log1p(x);
+        std_res = std::log1p(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+    }
+
+    void test_atanh()
+    {
+        double x, rtl_res, std_res;
+        x = -2.0;
+        rtl_res = rtl::math::atanh(x); // NaN
+        std_res = std::atanh(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+        x = -1.0;
+        rtl_res = rtl::math::atanh(x); // -Inf
+        std_res = std::atanh(x);
+        CPPUNIT_ASSERT_EQUAL(std::signbit(rtl_res), std::signbit(std_res));
+        CPPUNIT_ASSERT_EQUAL(std::isinf(rtl_res), std::isinf(std_res));
+        x = 0.0;
+        rtl_res = rtl::math::atanh(x);
+        std_res = std::atanh(x);
+        CPPUNIT_ASSERT_EQUAL(rtl_res, std_res);
+        x = 1.0;
+        rtl_res = rtl::math::atanh(1.0); // +Inf
+        std_res = std::atanh(x);
+        CPPUNIT_ASSERT_EQUAL(std::signbit(rtl_res), std::signbit(std_res));
+        CPPUNIT_ASSERT_EQUAL(std::isinf(rtl_res), std::isinf(std_res));
+        x = 2.0;
+        rtl_res = rtl::math::atanh(2.0); // NaN
+        std_res = std::atanh(x);
+        CPPUNIT_ASSERT_EQUAL(std::isnan(rtl_res), std::isnan(std_res));
+    }
+
+    CPPUNIT_TEST_SUITE(Test);
+    CPPUNIT_TEST(test_erf);
+    CPPUNIT_TEST(test_erfc);
+    CPPUNIT_TEST(test_expm1);
+    CPPUNIT_TEST(test_log1p);
+    CPPUNIT_TEST(test_atanh);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
\ No newline at end of file

Reply via email to