summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-10-01 09:17:03 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-10-01 19:36:41 +0200
commitde80116e81a5b73215098cd0aa60ac9226905ae5 (patch)
tree67b858d144d74c1d21546078037b481750dc81b1 /sal
parentff842adedb6621ff338defab3c9c4c1022ca8bdf (diff)
Simplify the code a bit to clarify the logic
Change-Id: I80201148684f6e297ff0c880c0dbbc346129a557 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122864 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/math.cxx64
1 files changed, 24 insertions, 40 deletions
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 2d1c1257ef97..f6a2b15a21d4 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -580,64 +580,48 @@ void doubleToString(typename T::String ** pResult,
if (nDigit >= 10)
{ // after-treatment of up-rounding to the next decade
- sal_Int32 sLen = p - pBuf - 1;
- if (sLen == -1 || (sLen == 0 && bSign))
+ typename T::Char* p1 = pBuf;
+ // Assert that no one changed the logic we rely on.
+ assert(!bSign || *p1 == '-');
+ // Do not touch leading minus sign put earlier.
+ if (bSign)
+ ++p1;
+ assert(p1 <= p);
+ if (p1 == p)
{
- // Assert that no one changed the logic we rely on.
- assert(!bSign || pBuf[0] == '-');
- p = pBuf;
- if (bSign)
- ++p;
- if (eFormat == rtl_math_StringFormat_F)
+ *p++ = '1';
+ if (eFormat != rtl_math_StringFormat_F)
{
- *p++ = '1';
- *p++ = '0';
- }
- else
- {
- *p++ = '1';
*p++ = cDecSeparator;
- *p++ = '0';
nExp++;
bHasDec = true;
}
+ *p++ = '0';
}
else
{
- for (sal_Int32 j = sLen; j >= 0; j--)
+ for (typename T::Char* p2 = p - 1; p2 >= p1; --p2)
{
- typename T::Char* p2 = &pBuf[j];
typename T::Char cS = *p2;
- if (j == 0 && bSign)
+ if (cS == cDecSeparator)
+ continue;
+ if (cS != '9')
{
- // Do not touch leading minus sign put earlier.
- assert(cS == '-');
- break; // for, this is the last character backwards.
+ ++*p2;
+ break;
}
- if (cS != cDecSeparator)
+ *p2 = '0';
+ if (p2 == p1) // The number consisted of all 9s replaced to all 0s
{
- if (cS != '9')
- {
- *p2 = ++cS;
- j = -1; // break loop
+ if (eFormat == rtl_math_StringFormat_F)
+ { // move everything to the right before inserting '1'
+ std::memmove(p2 + 1, p2, (p++ - p2) * sizeof(*p));
}
else
{
- *p2 = '0';
- if (j == 0 || (j == 1 && bSign))
- {
- if (eFormat == rtl_math_StringFormat_F)
- { // insert '1'
- std::memmove(p2 + 1, p2, (p++ - p2) * sizeof(*p));
- *p2 = '1';
- }
- else
- {
- *p2 = '1';
- nExp++;
- }
- }
+ nExp++;
}
+ *p2 = '1';
}
}