diff options
author | Eike Rathke <erack@redhat.com> | 2020-11-27 17:55:37 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2020-11-28 12:26:24 +0100 |
commit | 87191b03e79e909a8ace3bcac35cfeea7f0d34ea (patch) | |
tree | cd4173bab3e9f7289c2400f8243b6da8547ea490 /sal | |
parent | 8e717facb376029e24dbf39c171234d67388d4d5 (diff) |
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 <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 88 |
1 files changed, 88 insertions, 0 deletions
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() { |