diff options
author | Eike Rathke <erack@redhat.com> | 2016-01-13 14:45:29 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-01-13 14:47:58 +0100 |
commit | a3f5f4f6369552a3da870de1ed4ea9d8c628c7a8 (patch) | |
tree | 7365cc8581ea27990d429dfc97c2724fe6e20ad1 /sal | |
parent | 0f6203edf74832f84d8263d7a544d679203a4efc (diff) |
unit test for tdf#96918 display accurate integer double values
Change-Id: I619e0cb0fbbfd0dfba3b2fe9c3476be55a3eea8e
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index aa7b213fdecd..663693416639 100644 --- a/sal/qa/rtl/math/test-rtl-math.cxx +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -88,6 +88,46 @@ public: CPPUNIT_ASSERT_EQUAL(0.0, res); } + void test_doubleToString() { + double fVal = 999999999999999; + sal_Int32 aGroups[3] = { 3, 2, 0 }; + rtl::OUString aRes( rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, + '.', aGroups, ',', true)); + CPPUNIT_ASSERT_EQUAL( OUString("99,99,99,99,99,99,999"), aRes); + + fVal = 4503599627370495; + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false); + CPPUNIT_ASSERT_EQUAL( OUString("4503599627370495"), aRes); + + fVal = 4503599627370496; + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + 2, '.', false); + CPPUNIT_ASSERT_EQUAL( OUString("4503599627370496.00"), aRes); + + fVal = 9007199254740991; // (2^53)-1 + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("9007199254740991"), aRes); + + fVal = 9007199254740992; // (2^53), algorithm switch + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("9.00719925474099E+015"), aRes); + + fVal = 9007199254740993; // (2^53)+1 would be but is 9007199254740992 + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("9.00719925474099E+015"), aRes); + } + void test_erf() { double x, res; x = 0.0; @@ -176,6 +216,7 @@ public: CPPUNIT_TEST(test_stringToDouble_good); CPPUNIT_TEST(test_stringToDouble_bad); CPPUNIT_TEST(test_stringToDouble_exponent_without_digit); + CPPUNIT_TEST(test_doubleToString); CPPUNIT_TEST(test_erf); CPPUNIT_TEST(test_erfc); CPPUNIT_TEST(test_expm1); |