| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 static const int kSignificandSize = 64; | 44 static const int kSignificandSize = 64; |
| 45 | 45 |
| 46 DiyFp() : f_(0), e_(0) {} | 46 DiyFp() : f_(0), e_(0) {} |
| 47 DiyFp(uint64_t f, int e) : f_(f), e_(e) {} | 47 DiyFp(uint64_t f, int e) : f_(f), e_(e) {} |
| 48 | 48 |
| 49 // this = this - other. | 49 // this = this - other. |
| 50 // The exponents of both numbers must be the same and the significand of this | 50 // The exponents of both numbers must be the same and the significand of this |
| 51 // must be bigger than the significand of other. | 51 // must be bigger than the significand of other. |
| 52 // The result will not be normalized. | 52 // The result will not be normalized. |
| 53 void Subtract(const DiyFp& other) { | 53 void Subtract(const DiyFp& other) { |
| 54 ASSERT(e_ == other.e_); | 54 DCHECK_EQ(e_, other.e_); |
| 55 ASSERT(f_ >= other.f_); | 55 DCHECK_GE(f_, other.f_); |
| 56 f_ -= other.f_; | 56 f_ -= other.f_; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Returns a - b. | 59 // Returns a - b. |
| 60 // The exponents of both numbers must be the same and this must be bigger | 60 // The exponents of both numbers must be the same and this must be bigger |
| 61 // than other. The result will not be normalized. | 61 // than other. The result will not be normalized. |
| 62 static DiyFp Minus(const DiyFp& a, const DiyFp& b) { | 62 static DiyFp Minus(const DiyFp& a, const DiyFp& b) { |
| 63 DiyFp result = a; | 63 DiyFp result = a; |
| 64 result.Subtract(b); | 64 result.Subtract(b); |
| 65 return result; | 65 return result; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // this = this * other. | 68 // this = this * other. |
| 69 void Multiply(const DiyFp& other); | 69 void Multiply(const DiyFp& other); |
| 70 | 70 |
| 71 // returns a * b; | 71 // returns a * b; |
| 72 static DiyFp Times(const DiyFp& a, const DiyFp& b) { | 72 static DiyFp Times(const DiyFp& a, const DiyFp& b) { |
| 73 DiyFp result = a; | 73 DiyFp result = a; |
| 74 result.Multiply(b); | 74 result.Multiply(b); |
| 75 return result; | 75 return result; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void Normalize() { | 78 void Normalize() { |
| 79 ASSERT(f_ != 0); | 79 DCHECK_NE(f_, 0u); |
| 80 uint64_t f = f_; | 80 uint64_t f = f_; |
| 81 int e = e_; | 81 int e = e_; |
| 82 | 82 |
| 83 // This method is mainly called for normalizing boundaries. In general | 83 // This method is mainly called for normalizing boundaries. In general |
| 84 // boundaries need to be shifted by 10 bits. We thus optimize for this case. | 84 // boundaries need to be shifted by 10 bits. We thus optimize for this case. |
| 85 const uint64_t k10MSBits = UINT64_2PART_C(0xFFC00000, 00000000); | 85 const uint64_t k10MSBits = UINT64_2PART_C(0xFFC00000, 00000000); |
| 86 while ((f & k10MSBits) == 0) { | 86 while ((f & k10MSBits) == 0) { |
| 87 f <<= 10; | 87 f <<= 10; |
| 88 e -= 10; | 88 e -= 10; |
| 89 } | 89 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 | 112 |
| 113 uint64_t f_; | 113 uint64_t f_; |
| 114 int e_; | 114 int e_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 } // namespace double_conversion | 117 } // namespace double_conversion |
| 118 | 118 |
| 119 } // namespace WTF | 119 } // namespace WTF |
| 120 | 120 |
| 121 #endif // DOUBLE_CONVERSION_DIY_FP_H_ | 121 #endif // DOUBLE_CONVERSION_DIY_FP_H_ |
| OLD | NEW |