Index: Source/platform/Decimal.cpp |
diff --git a/Source/platform/Decimal.cpp b/Source/platform/Decimal.cpp |
index 02dca8f3691710782a6f9cfc4b41c1d36f4b8272..e1537a793dc63c8a2af91e74ddcd24e5f895de76 100644 |
--- a/Source/platform/Decimal.cpp |
+++ b/Source/platform/Decimal.cpp |
@@ -612,6 +612,11 @@ Decimal::AlignedOperands Decimal::alignOperands(const Decimal& lhs, const Decima |
return alignedOperands; |
} |
+static bool isMultiplePowersOfTen(uint64_t coefficient, int n) |
+{ |
+ return !coefficient || !(coefficient % scaleUp(1, n)); |
+} |
+ |
// Round toward positive infinity. |
// Note: Mac ports defines ceil(x) as wtf_ceil(x), so we can't use name "ceil" here. |
Decimal Decimal::ceiling() const |
@@ -628,10 +633,9 @@ Decimal Decimal::ceiling() const |
if (numberOfDigits < numberOfDropDigits) |
return isPositive() ? Decimal(1) : zero(Positive); |
- result = scaleDown(result, numberOfDropDigits - 1); |
- if (sign() == Positive && result % 10 > 0) |
- result += 10; |
- result /= 10; |
+ result = scaleDown(result, numberOfDropDigits); |
+ if (isPositive() && !isMultiplePowersOfTen(m_data.coefficient(), numberOfDropDigits)) |
+ ++result; |
return Decimal(sign(), 0, result); |
} |
@@ -670,10 +674,9 @@ Decimal Decimal::floor() const |
if (numberOfDigits < numberOfDropDigits) |
return isPositive() ? zero(Positive) : Decimal(-1); |
- result = scaleDown(result, numberOfDropDigits - 1); |
- if (isNegative() && result % 10 > 0) |
- result += 10; |
- result /= 10; |
+ result = scaleDown(result, numberOfDropDigits); |
+ if (isNegative() && !isMultiplePowersOfTen(m_data.coefficient(), numberOfDropDigits)) |
+ ++result; |
return Decimal(sign(), 0, result); |
} |