summaryrefslogtreecommitdiff
path: root/sal/qa
diff options
context:
space:
mode:
authorLiu Hao <ianahao331@gmail.com>2022-08-22 23:32:00 +0800
committerStephan Bergmann <sbergman@redhat.com>2022-08-23 08:44:48 +0200
commite3d120e2ba991897bf7d8eff6cc4eba00f7d749e (patch)
treef930d5bab7794413be9f1b8bf0203feebb8c8775 /sal/qa
parentfe2fcbf0e564e2b0d8f3dbec326d3423bc5fbcf5 (diff)
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 <sbergman@redhat.com>
Diffstat (limited to 'sal/qa')
-rw-r--r--sal/qa/rtl/math/test-rtl-math.cxx58
-rw-r--r--sal/qa/rtl/math/test-std-math.cxx195
2 files changed, 224 insertions, 29 deletions
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