diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2017-12-10 01:17:49 +0900 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-01-23 14:39:28 +0100 |
commit | f16fdfa559ab62ccde2c2c0cbe1fc9e5ca2f3630 (patch) | |
tree | f04b42cff1f525f9913c7740c68b1f7cb4eb4ce9 /sal | |
parent | a6b53b5461c7d1ad2895d25691661f865bdb183e (diff) |
Add unit tests for rtl::math's inverse hyperbolic functions
based on i#97605's test cases.
Change-Id: Id7e57914553ba8801a624f667979badc191108e5
Reviewed-on: https://gerrit.libreoffice.org/46152
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index 116cc6009fcc..3e718940b097 100644 --- a/sal/qa/rtl/math/test-rtl-math.cxx +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -25,6 +25,7 @@ #include <rtl/math.hxx> #include <rtl/ustring.h> #include <rtl/ustring.hxx> +#include <limits> CPPUNIT_NS_BEGIN @@ -344,6 +345,73 @@ public: CPPUNIT_ASSERT_EQUAL(true,rtl::math::isNan(res)); } + void test_acosh() { + double res; + + res = rtl::math::acosh(-1.0); // NaN + CPPUNIT_ASSERT(rtl::math::isNan(res)); + + res = rtl::math::acosh(0.0); // NaN + CPPUNIT_ASSERT(rtl::math::isNan(res)); + + res = rtl::math::acosh(0.5); // NaN + CPPUNIT_ASSERT(rtl::math::isNan(res)); + + CPPUNIT_ASSERT_EQUAL(0.0, rtl::math::acosh(1.0)); + + res = rtl::math::acosh(std::numeric_limits<double>::infinity()); // +Inf + CPPUNIT_ASSERT(!rtl::math::isSignBitSet(res)); + CPPUNIT_ASSERT(rtl::math::isInf(res)); + + // #i97605 + CPPUNIT_ASSERT_DOUBLES_EQUAL(692.56728736744176, rtl::math::acosh(3e+300), 1e-15); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.014142017775252324, rtl::math::acosh(1.0001), 1e-15); + } + + void test_asinh() { + double res; + + res = rtl::math::asinh(-std::numeric_limits<double>::infinity()); // -Inf + CPPUNIT_ASSERT(rtl::math::isSignBitSet(res)); + CPPUNIT_ASSERT(rtl::math::isInf(res)); + + CPPUNIT_ASSERT_EQUAL(0.0, rtl::math::asinh(0.0)); + + res = rtl::math::asinh(std::numeric_limits<double>::infinity()); // +Inf + CPPUNIT_ASSERT(!rtl::math::isSignBitSet(res)); + CPPUNIT_ASSERT(rtl::math::isInf(res)); + + // #i97605 + CPPUNIT_ASSERT_DOUBLES_EQUAL(691.67568924815798, rtl::math::asinh(1.23e+300), 1e-15); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0350378961923076, rtl::math::asinh(1.23), 1e-16); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23e-300, rtl::math::asinh(1.23e-300), 1e-303); + + // asinh is an odd function + CPPUNIT_ASSERT_EQUAL(-rtl::math::asinh(1.23e+300), rtl::math::asinh(-1.23e+300)); + CPPUNIT_ASSERT_EQUAL(-rtl::math::asinh(1.23), rtl::math::asinh(-1.23)); + CPPUNIT_ASSERT_EQUAL(-rtl::math::asinh(1.23e-300), rtl::math::asinh(-1.23e-300)); + } + + void test_atanh() { + double res; + + res = rtl::math::atanh(-2.0); // NaN + CPPUNIT_ASSERT(rtl::math::isNan(res)); + + res = rtl::math::atanh(-1.0); // -Inf + CPPUNIT_ASSERT(rtl::math::isSignBitSet(res)); + CPPUNIT_ASSERT(rtl::math::isInf(res)); + + CPPUNIT_ASSERT_EQUAL(0.0, rtl::math::atanh(0.0)); + + res = rtl::math::atanh(1.0); // +Inf + CPPUNIT_ASSERT(!rtl::math::isSignBitSet(res)); + CPPUNIT_ASSERT(rtl::math::isInf(res)); + + res = rtl::math::atanh(2.0); // NaN + CPPUNIT_ASSERT(rtl::math::isNan(res)); + } + CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(test_stringToDouble_good); CPPUNIT_TEST(test_stringToDouble_bad); @@ -354,6 +422,9 @@ public: CPPUNIT_TEST(test_expm1); CPPUNIT_TEST(test_log1p); CPPUNIT_TEST(test_approx); + CPPUNIT_TEST(test_acosh); + CPPUNIT_TEST(test_asinh); + CPPUNIT_TEST(test_atanh); CPPUNIT_TEST_SUITE_END(); }; |