[Libreoffice-commits] core.git: 4 commits - sal/qa sal/rtl

Eike Rathke erack at redhat.com
Thu Jan 14 11:53:57 PST 2016


 sal/qa/rtl/math/test-rtl-math.cxx |   14 ++++++++++++++
 sal/rtl/math.cxx                  |   27 +++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)

New commits:
commit f19b4826c44e9e5f54b968fef59a3fcd3007d522
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Jan 14 20:52:15 2016 +0100

    use ::std::swap() to reverse buffer
    
    Change-Id: I7e18e57636416f0a3ed96c2fa3adc004fb3ba013

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index f193eed..63aa657 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -270,9 +270,7 @@ inline void doubleToString(StringT ** pResult,
             sal_Int32 n = (p - pBuf) / 2;
             for (sal_Int32 i=0; i < n; ++i)
             {
-                typename T::Char c = p[-i-1];
-                p[-i-1] = pBuf[i];
-                pBuf[i] = c;
+                ::std::swap( pBuf[i], p[-i-1]);
             }
             // Append decimals.
             if (nDecPlaces > 0)
commit e6c9bdfdc181c95d5757b96b6194d639a0df3c79
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Jan 14 20:48:44 2016 +0100

    use getN10Exp(x) instead of pow(10.0,x)
    
    Change-Id: Ib7e49126cbffc510fa941c25a8d57222bad51c46

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index e621c48..f193eed 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -228,7 +228,7 @@ inline void doubleToString(StringT ** pResult,
             // Round before decimal position.
             if (nDecPlaces < 0)
             {
-                sal_Int64 nRounding = static_cast<sal_Int64>( pow( 10.0, static_cast<double>( -nDecPlaces - 1)));
+                sal_Int64 nRounding = static_cast<sal_Int64>( getN10Exp( -nDecPlaces - 1));
                 sal_Int64 nTemp = nInt / nRounding;
                 int nDigit = nTemp % 10;
                 nTemp /= 10;
commit 5299400e5cce3060a0de85bb4dedd065b5ad1f41
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Jan 14 20:27:30 2016 +0100

    unit test for negative decimal places rounding, tdf#96918 related
    
    Change-Id: Ib2f3ffaa7c4216b66479c750465c2beab927405a

diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx
index 47736f1..3de4956 100644
--- a/sal/qa/rtl/math/test-rtl-math.cxx
+++ b/sal/qa/rtl/math/test-rtl-math.cxx
@@ -97,6 +97,20 @@ public:
                     '.', aGroups, ',', true));
         CPPUNIT_ASSERT_EQUAL( OUString("99,99,99,99,99,99,999"), aRes);
 
+        fVal = 949.0;
+        aRes = rtl::math::doubleToUString( fVal,
+                    rtl_math_StringFormat_Automatic,
+                    -2,     // round before decimals
+                    '.', aGroups, ',', true);
+        CPPUNIT_ASSERT_EQUAL( OUString("900"), aRes);
+
+        fVal = 950.0;
+        aRes = rtl::math::doubleToUString( fVal,
+                    rtl_math_StringFormat_Automatic,
+                    -2,     // round before decimals
+                    '.', aGroups, ',', true);
+        CPPUNIT_ASSERT_EQUAL( OUString("1,000"), aRes);
+
         fVal = 4503599627370495.0;
         aRes = rtl::math::doubleToUString( fVal,
                     rtl_math_StringFormat_Automatic,
commit fdf982f70b2944053d995baaa3d78c7cdc4bbc4b
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Jan 14 20:25:01 2016 +0100

    handle negative decimal places for rounding, tdf#96918 related
    
    Change-Id: Ifa423eabc64ead519c4f4a3370a06e88ea5c7466

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index f382267..e621c48 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -218,10 +218,27 @@ inline void doubleToString(StringT ** pResult,
         // true within the precision range.
         if (nInt <= kMaxInt && static_cast<double>(nInt) == fValue)
         {
-            if (nDecPlaces == rtl_math_DecimalPlaces_Max || bEraseTrailingDecZeros)
+            if (nDecPlaces == rtl_math_DecimalPlaces_Max)
                 nDecPlaces = 0;
             else
-                nDecPlaces = ::std::min<sal_Int32>(nDecPlaces, 15);
+                nDecPlaces = ::std::max<sal_Int32>( ::std::min<sal_Int32>( nDecPlaces, 15), -15);
+            if (bEraseTrailingDecZeros && nDecPlaces > 0)
+                nDecPlaces = 0;
+
+            // Round before decimal position.
+            if (nDecPlaces < 0)
+            {
+                sal_Int64 nRounding = static_cast<sal_Int64>( pow( 10.0, static_cast<double>( -nDecPlaces - 1)));
+                sal_Int64 nTemp = nInt / nRounding;
+                int nDigit = nTemp % 10;
+                nTemp /= 10;
+                if (nDigit >= 5)
+                    ++nTemp;
+                nTemp *= 10;
+                nTemp *= nRounding;
+                nInt = nTemp;
+                nDecPlaces = 0;
+            }
 
             // Max 1 sign, 16 integer digits, 15 group separators, 1 decimal
             // separator, 15 decimals digits.
@@ -258,7 +275,7 @@ inline void doubleToString(StringT ** pResult,
                 pBuf[i] = c;
             }
             // Append decimals.
-            if (nDecPlaces)
+            if (nDecPlaces > 0)
             {
                 *p++ = cDecSeparator;
                 while (nDecPlaces--)


More information about the Libreoffice-commits mailing list