sal/qa/rtl/math/test-rtl-math.cxx |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

New commits:
commit 2fd915b7d2d2a9e25600a07587ab01d23bffbc58
Author:     Eike Rathke <[email protected]>
AuthorDate: Wed Mar 15 17:37:14 2023 +0100
Commit:     Eike Rathke <[email protected]>
CommitDate: Wed Mar 15 19:55:32 2023 +0000

    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 <[email protected]>
    Tested-by: Jenkins

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();
 };
 

Reply via email to