Kaydet (Commit) f16fdfa5 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Eike Rathke

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/46152Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
üst a6b53b54
......@@ -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();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment