sal/qa/rtl/math/test-rtl-math.cxx | 88 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+)
New commits: commit 87191b03e79e909a8ace3bcac35cfeea7f0d34ea Author: Eike Rathke <er...@redhat.com> AuthorDate: Fri Nov 27 17:55:37 2020 +0100 Commit: Eike Rathke <er...@redhat.com> CommitDate: Sat Nov 28 12:26:24 2020 +0100 Unit tests for DBL_MAX to string conversion, tdf#136272 Change-Id: Ied41d1e21fb6e40b54adac3c33fa0d096e25bada Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106783 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index 4843d66c2aec..799787e9d4a9 100644 --- a/sal/qa/rtl/math/test-rtl-math.cxx +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -185,6 +185,37 @@ public: CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_OutOfRange, status); CPPUNIT_ASSERT_EQUAL(sal_Int32(12), end); CPPUNIT_ASSERT_EQUAL(std::numeric_limits<double>::infinity(), res); + + // DBL_MAX and 4 nextafters + double fValAfter = DBL_MAX; + res = rtl::math::stringToDouble(OUString("1.7976931348623157e+308"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end); + CPPUNIT_ASSERT_EQUAL(fValAfter, res); + + fValAfter = std::nextafter( fValAfter, 0); + res = rtl::math::stringToDouble(OUString("1.7976931348623155e+308"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end); + CPPUNIT_ASSERT_EQUAL(fValAfter, res); + + fValAfter = std::nextafter( fValAfter, 0); + res = rtl::math::stringToDouble(OUString("1.7976931348623153e+308"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end); + CPPUNIT_ASSERT_EQUAL(fValAfter, res); + + fValAfter = std::nextafter( fValAfter, 0); + res = rtl::math::stringToDouble(OUString("1.7976931348623151e+308"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end); + CPPUNIT_ASSERT_EQUAL(fValAfter, res); + + fValAfter = std::nextafter( fValAfter, 0); + res = rtl::math::stringToDouble(OUString("1.7976931348623149e+308"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end); + CPPUNIT_ASSERT_EQUAL(fValAfter, res); } void test_stringToDouble_bad() { @@ -329,6 +360,63 @@ public: fVal = 12345.6789; aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, -3, '.', true); CPPUNIT_ASSERT_EQUAL( OUString("1.2E+004"), aRes); + + // DBL_MAX and 4 nextafters + fVal = DBL_MAX; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.7976931348623157E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.7976931348623155E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.7976931348623153E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.7976931348623151E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.7976931348623149E+308"), aRes); + + // DBL_MAX and 4 nextafters rounded to 15 decimals + fVal = DBL_MAX; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, 15, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.797693134862316E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, 15, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.797693134862316E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, 15, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.797693134862315E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, 15, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.797693134862315E+308"), aRes); + + fVal = std::nextafter( fVal, 0); + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, 15, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.797693134862315E+308"), aRes); + + // DBL_MAX rounded to 14 decimals + fVal = DBL_MAX; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, 14, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.79769313486232E+308"), aRes); + + // DBL_MAX rounded to 2 decimals + fVal = DBL_MAX; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, 2, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.80E+308"), aRes); } void test_approx() { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits