summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2023-03-15 17:37:14 +0100
committerEike Rathke <erack@redhat.com>2023-03-15 19:55:32 +0000
commit2fd915b7d2d2a9e25600a07587ab01d23bffbc58 (patch)
treecdb12092ac82da0606cc83c8dea19c91bc59966f
parentebaccbd0acc41bfb6c1a1321656679b18026d983 (diff)
Related: tdf#152943 Test that a quiet NaN payload is propagated
Change-Id: Ib98b507db9305ed20e3000f7f457a135a3bb3836 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148936 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
-rw-r--r--sal/qa/rtl/math/test-rtl-math.cxx24
1 files changed, 24 insertions, 0 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx
index f0288fd50e0e..57ac2a2616f0 100644
--- a/sal/qa/rtl/math/test-rtl-math.cxx
+++ b/sal/qa/rtl/math/test-rtl-math.cxx
@@ -642,6 +642,29 @@ public:
CPPUNIT_ASSERT(std::isnan(res));
}
+ void test_payloadNaN() {
+ // Test that a quiet NaN payload is propagated and behaves as we
+ // expect. Ideally that could be done with a constexpr in
+ // sal/rtl/math.cxx to fail already during compile time instead of make
+ // check, but..
+ // See
+ // https://grouper.ieee.org/groups/msc/ANSI_IEEE-Std-754-2019/background/nan-propagation.pdf
+ double fVal1 = std::numeric_limits<double>::quiet_NaN();
+ reinterpret_cast<sal_math_Double*>(&fVal1)->nan_parts.fraction_lo = 0xbeef;
+ const double fVal2 = 0 + fVal1;
+ CPPUNIT_ASSERT(std::isnan(fVal2));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Your platform does not support propagation of NaN payloads.",
+ static_cast<sal_uInt32>(0xbeef),
+ static_cast<sal_uInt32>(reinterpret_cast<const sal_math_Double*>(&fVal2)->nan_parts.fraction_lo));
+ reinterpret_cast<sal_math_Double*>(&fVal1)->nan_parts.fraction_lo = 0xdead;
+ const double fVal3 = fVal1 + fVal2;
+ // Result is one of the payloaded NaNs but the standard does not
+ // specify which.
+ CPPUNIT_ASSERT_MESSAGE("Your platform does not support propagation of two combined NaN payloads.",
+ 0xbeef == reinterpret_cast<const sal_math_Double*>(&fVal3)->nan_parts.fraction_lo ||
+ 0xdead == reinterpret_cast<const sal_math_Double*>(&fVal3)->nan_parts.fraction_lo);
+ }
+
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(test_stringToDouble_good);
CPPUNIT_TEST(test_stringToDouble_bad);
@@ -656,6 +679,7 @@ public:
CPPUNIT_TEST(test_acosh);
CPPUNIT_TEST(test_asinh);
CPPUNIT_TEST(test_atanh);
+ CPPUNIT_TEST(test_payloadNaN);
CPPUNIT_TEST_SUITE_END();
};