[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sal/rtl

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 30 08:38:19 UTC 2019


 sal/rtl/math.cxx |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

New commits:
commit b7f62ed447ace5a6e7a0a5188cb72c635736b7f9
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Fri Aug 9 15:11:09 2019 +0200
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Fri Aug 30 10:37:36 2019 +0200

    Resolves: tdf#126766 fix rounding correction at start of negative values
    
    doubleToString() is entered with an inaccuracy afflicted
    fValue=-9999.9999999999927 for which the rounding into the next
    magnitude incremented the '-' character to '.' instead of
    appending a '1' (and '0' and then "000") thus yielded ".0000"
    instead of "-10000"
    
    This seems to have been always the case.
    
    Change-Id: I66170defa71fec40ca0b85f68affde8eff0d5ccb
    Reviewed-on: https://gerrit.libreoffice.org/77208
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit be8da97976658ff19b4dd010bff328cd3f424c1b)
    Reviewed-on: https://gerrit.libreoffice.org/77216
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    Reviewed-on: https://gerrit.libreoffice.org/77911
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 9fd7983f8787..18ee802316bb 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -546,9 +546,13 @@ void doubleToString(typename T::String ** pResult,
                 if (nDigit >= 10)
                 {   // after-treatment of up-rounding to the next decade
                     sal_Int32 sLen = static_cast< long >(p-pBuf)-1;
-                    if (sLen == -1)
+                    if (sLen == -1 || (sLen == 0 && bSign))
                     {
+                        // Assert that no one changed the logic we rely on.
+                        assert(!bSign || *pBuf == static_cast< typename T::Char >('-'));
                         p = pBuf;
+                        if (bSign)
+                            ++p;
                         if (eFormat == rtl_math_StringFormat_F)
                         {
                             *p++ = static_cast< typename T::Char >('1');
@@ -568,6 +572,12 @@ void doubleToString(typename T::String ** pResult,
                         for (sal_Int32 j = sLen; j >= 0; j--)
                         {
                             typename T::Char cS = pBuf[j];
+                            if (j == 0 && bSign)
+                            {
+                                // Do not touch leading minus sign put earlier.
+                                assert(cS == static_cast< typename T::Char >('-'));
+                                break;  // for, this is the last character backwards.
+                            }
                             if (cS != cDecSeparator)
                             {
                                 if (cS != static_cast< typename T::Char >('9'))
@@ -578,7 +588,7 @@ void doubleToString(typename T::String ** pResult,
                                 else
                                 {
                                     pBuf[j] = static_cast< typename T::Char >('0');
-                                    if (j == 0)
+                                    if (j == 0 || (j == 1 && bSign))
                                     {
                                         if (eFormat == rtl_math_StringFormat_F)
                                         {   // insert '1'


More information about the Libreoffice-commits mailing list