diff options
author | Eike Rathke <erack@redhat.com> | 2024-05-14 22:59:28 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2024-05-17 19:57:44 +0200 |
commit | 14e89d9f3fb2dfc46cc40595391c55f708fdac52 (patch) | |
tree | efa480cade18ced9d084706521b6ed37f11f0e5f /sal | |
parent | 91ef48ca9d30bf134719a28bfc4a6b23ec9e27d9 (diff) |
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 <erack@redhat.com>
(cherry picked from commit 1ea85e8f2d815e6c0834215714ed3dad1101b971)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167673
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/strtmpl.hxx | 5 |
1 files changed, 5 insertions, 0 deletions
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; } |