Chromium Code Reviews| Index: Source/platform/Decimal.cpp |
| diff --git a/Source/platform/Decimal.cpp b/Source/platform/Decimal.cpp |
| index 02dca8f3691710782a6f9cfc4b41c1d36f4b8272..45f69c3ae8a99f5e288cb2ee202fd24b1d6fe77f 100644 |
| --- a/Source/platform/Decimal.cpp |
| +++ b/Source/platform/Decimal.cpp |
| @@ -612,6 +612,21 @@ Decimal::AlignedOperands Decimal::alignOperands(const Decimal& lhs, const Decima |
| return alignedOperands; |
| } |
| +// Returns true if the 'n' least significant digits of |
| +// the coefficient are all zero. |
| +static bool digitsAllZero(uint64_t coefficient, int n) |
|
yosin_UTC9
2013/11/18 03:48:28
How about this?
static bool isMultipleOfTenPowerN
sof
2013/11/18 06:48:27
Yes, clearer too. Done + took the opportunity to s
|
| +{ |
| + ASSERT(n >= 0); |
| + while (n > 0) { |
| + if (coefficient % 10) { |
| + return false; |
| + } |
| + coefficient /= 10; |
| + n--; |
|
yosin_UTC9
2013/11/18 03:48:28
nit: --n
Other parts of this file use prefix decre
|
| + } |
| + return true; |
| +} |
| + |
| // 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 +643,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() && !digitsAllZero(m_data.coefficient(), numberOfDropDigits)) |
| + result++; |
|
yosin_UTC9
2013/11/18 03:48:28
nit: ++result
Other parts of this file use prefix
sof
2013/11/18 06:48:27
Done.
|
| return Decimal(sign(), 0, result); |
| } |
| @@ -670,10 +684,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() && !digitsAllZero(m_data.coefficient(), numberOfDropDigits)) |
| + result++; |
|
yosin_UTC9
2013/11/18 03:48:28
nit: ++result
Other parts of this file use prefix
sof
2013/11/18 06:48:27
Done.
|
| return Decimal(sign(), 0, result); |
| } |