OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return low | (static_cast<uint64_t>(high) << 32); | 149 return low | (static_cast<uint64_t>(high) << 32); |
150 } | 150 } |
151 | 151 |
152 static uint64_t MultiplyHigh(uint64_t, uint64_t); | 152 static uint64_t MultiplyHigh(uint64_t, uint64_t); |
153 | 153 |
154 uint64_t high_; | 154 uint64_t high_; |
155 uint64_t low_; | 155 uint64_t low_; |
156 }; | 156 }; |
157 | 157 |
158 UInt128& UInt128::operator/=(const uint32_t divisor) { | 158 UInt128& UInt128::operator/=(const uint32_t divisor) { |
159 ASSERT(divisor); | 159 DCHECK(divisor); |
160 | 160 |
161 if (!high_) { | 161 if (!high_) { |
162 low_ /= divisor; | 162 low_ /= divisor; |
163 return *this; | 163 return *this; |
164 } | 164 } |
165 | 165 |
166 uint32_t dividend[4]; | 166 uint32_t dividend[4]; |
167 dividend[0] = LowUInt32(low_); | 167 dividend[0] = LowUInt32(low_); |
168 dividend[1] = HighUInt32(low_); | 168 dividend[1] = HighUInt32(low_); |
169 dividend[2] = LowUInt32(high_); | 169 dividend[2] = LowUInt32(high_); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 case SpecialValueHandler::kEitherNaN: | 447 case SpecialValueHandler::kEitherNaN: |
448 return handler.Value(); | 448 return handler.Value(); |
449 | 449 |
450 case SpecialValueHandler::kLHSIsInfinity: | 450 case SpecialValueHandler::kLHSIsInfinity: |
451 return Infinity(result_sign); | 451 return Infinity(result_sign); |
452 | 452 |
453 case SpecialValueHandler::kRHSIsInfinity: | 453 case SpecialValueHandler::kRHSIsInfinity: |
454 return Zero(result_sign); | 454 return Zero(result_sign); |
455 } | 455 } |
456 | 456 |
457 ASSERT(lhs.IsFinite()); | 457 DCHECK(lhs.IsFinite()); |
458 ASSERT(rhs.IsFinite()); | 458 DCHECK(rhs.IsFinite()); |
459 | 459 |
460 if (rhs.IsZero()) | 460 if (rhs.IsZero()) |
461 return lhs.IsZero() ? Nan() : Infinity(result_sign); | 461 return lhs.IsZero() ? Nan() : Infinity(result_sign); |
462 | 462 |
463 int result_exponent = lhs.Exponent() - rhs.Exponent(); | 463 int result_exponent = lhs.Exponent() - rhs.Exponent(); |
464 | 464 |
465 if (lhs.IsZero()) | 465 if (lhs.IsZero()) |
466 return Decimal(result_sign, result_exponent, 0); | 466 return Decimal(result_sign, result_exponent, 0); |
467 | 467 |
468 uint64_t remainder = lhs.data_.Coefficient(); | 468 uint64_t remainder = lhs.data_.Coefficient(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } | 537 } |
538 | 538 |
539 Decimal Decimal::Abs() const { | 539 Decimal Decimal::Abs() const { |
540 Decimal result(*this); | 540 Decimal result(*this); |
541 result.data_.SetSign(kPositive); | 541 result.data_.SetSign(kPositive); |
542 return result; | 542 return result; |
543 } | 543 } |
544 | 544 |
545 Decimal::AlignedOperands Decimal::AlignOperands(const Decimal& lhs, | 545 Decimal::AlignedOperands Decimal::AlignOperands(const Decimal& lhs, |
546 const Decimal& rhs) { | 546 const Decimal& rhs) { |
547 ASSERT(lhs.IsFinite()); | 547 DCHECK(lhs.IsFinite()); |
548 ASSERT(rhs.IsFinite()); | 548 DCHECK(rhs.IsFinite()); |
549 | 549 |
550 const int lhs_exponent = lhs.Exponent(); | 550 const int lhs_exponent = lhs.Exponent(); |
551 const int rhs_exponent = rhs.Exponent(); | 551 const int rhs_exponent = rhs.Exponent(); |
552 int exponent = std::min(lhs_exponent, rhs_exponent); | 552 int exponent = std::min(lhs_exponent, rhs_exponent); |
553 uint64_t lhs_coefficient = lhs.data_.Coefficient(); | 553 uint64_t lhs_coefficient = lhs.data_.Coefficient(); |
554 uint64_t rhs_coefficient = rhs.data_.Coefficient(); | 554 uint64_t rhs_coefficient = rhs.data_.Coefficient(); |
555 | 555 |
556 if (lhs_exponent > rhs_exponent) { | 556 if (lhs_exponent > rhs_exponent) { |
557 const int number_of_lhs_digits = CountDigits(lhs_coefficient); | 557 const int number_of_lhs_digits = CountDigits(lhs_coefficient); |
558 if (number_of_lhs_digits) { | 558 if (number_of_lhs_digits) { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 Decimal::EncodedData data = decimal.Value(); | 1001 Decimal::EncodedData data = decimal.Value(); |
1002 return ostream << "encode(" | 1002 return ostream << "encode(" |
1003 << String::Number(data.Coefficient()).Ascii().data() << ", " | 1003 << String::Number(data.Coefficient()).Ascii().data() << ", " |
1004 << String::Number(data.Exponent()).Ascii().data() << ", " | 1004 << String::Number(data.Exponent()).Ascii().data() << ", " |
1005 << (data.GetSign() == Decimal::kNegative ? "Negative" | 1005 << (data.GetSign() == Decimal::kNegative ? "Negative" |
1006 : "Positive") | 1006 : "Positive") |
1007 << ")=" << decimal.ToString().Ascii().data(); | 1007 << ")=" << decimal.ToString().Ascii().data(); |
1008 } | 1008 } |
1009 | 1009 |
1010 } // namespace blink | 1010 } // namespace blink |
OLD | NEW |