sal/rtl/strtmpl.hxx | 5 +++++
1 file changed, 5 insertions(+)
New commits:
commit 49a69504963812d8e2bd7d9a7de6c011a5749dda
Author: Eike Rathke <[email protected]>
AuthorDate: Tue May 14 22:59:28 2024 +0200
Commit: Xisco Fauli <[email protected]>
CommitDate: Wed May 15 21:29:17 2024 +0200
Resolves: tdf#160985 Max integer representation for rtl_math_StringFormat_G
Same as for rtl_math_StringFormat_Automatic we want to preserve
the highest accuracy of integer values also with
rtl_math_StringFormat_G if nDecPlaces is large enough, instead of
possibly rounding into 15 digits. This occurred with
FastSaxSerializer::write(double) but rtl::OString::number(double)
and rtl::OUString::number(double) and rtl_math_doubleToString()
and rtl::str::valueOfFP() and rtl_str_valueOfDouble() and all
places calling with rtl_math_StringFormat_G are similar affected.
Question might remain why those places use
rtl_math_StringFormat_G with fixed nDecimalPlaces calculated from
RTL_STR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1
instead of rtl_math_StringFormat_Automatic with
rtl_math_DecimalPlaces_Max.
Change-Id: Ib388b119faed441c9020dca803649a4089da5b07
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167647
Tested-by: Jenkins
Reviewed-by: Eike Rathke <[email protected]>
(cherry picked from commit 1ea85e8f2d815e6c0834215714ed3dad1101b971)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167673
Reviewed-by: Xisco Fauli <[email protected]>
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index 6414115d4174..8c63f1081f9c 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -1527,6 +1527,11 @@ void doubleToString(rtl_tString** pResult, sal_Int32*
pResultCapacity, sal_Int32
}
else
{
+ if (nOrigDigits <= nDecPlaces && aParts.exponent >= 0 &&
fValue < 0x1p53)
+ {
+ // Use integer representation with highest accuracy.
+ nRoundDigits = nOrigDigits; // no rounding
+ }
nDecPlaces = std::max<sal_Int32>(0, nDecPlaces - nExp - 1);
eFormat = rtl_math_StringFormat_F;
}