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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 static const int kSignificandSize = 53; | 53 static const int kSignificandSize = 53; |
54 | 54 |
55 Double() : d64_(0) {} | 55 Double() : d64_(0) {} |
56 explicit Double(double d) : d64_(double_to_uint64(d)) {} | 56 explicit Double(double d) : d64_(double_to_uint64(d)) {} |
57 explicit Double(uint64_t d64) : d64_(d64) {} | 57 explicit Double(uint64_t d64) : d64_(d64) {} |
58 explicit Double(DiyFp diy_fp) : d64_(DiyFpToUint64(diy_fp)) {} | 58 explicit Double(DiyFp diy_fp) : d64_(DiyFpToUint64(diy_fp)) {} |
59 | 59 |
60 // The value encoded by this Double must be greater or equal to +0.0. | 60 // The value encoded by this Double must be greater or equal to +0.0. |
61 // It must not be special (infinity, or NaN). | 61 // It must not be special (infinity, or NaN). |
62 DiyFp AsDiyFp() const { | 62 DiyFp AsDiyFp() const { |
63 ASSERT(Sign() > 0); | 63 DCHECK_GT(Sign(), 0); |
64 ASSERT(!IsSpecial()); | 64 DCHECK(!IsSpecial()); |
65 return DiyFp(Significand(), Exponent()); | 65 return DiyFp(Significand(), Exponent()); |
66 } | 66 } |
67 | 67 |
68 // The value encoded by this Double must be strictly greater than 0. | 68 // The value encoded by this Double must be strictly greater than 0. |
69 DiyFp AsNormalizedDiyFp() const { | 69 DiyFp AsNormalizedDiyFp() const { |
70 ASSERT(value() > 0.0); | 70 DCHECK_GT(value(), 0.0); |
71 uint64_t f = Significand(); | 71 uint64_t f = Significand(); |
72 int e = Exponent(); | 72 int e = Exponent(); |
73 | 73 |
74 // The current double could be a denormal. | 74 // The current double could be a denormal. |
75 while ((f & kHiddenBit) == 0) { | 75 while ((f & kHiddenBit) == 0) { |
76 f <<= 1; | 76 f <<= 1; |
77 e--; | 77 e--; |
78 } | 78 } |
79 // Do the final shifts in one go. | 79 // Do the final shifts in one go. |
80 f <<= DiyFp::kSignificandSize - kSignificandSize; | 80 f <<= DiyFp::kSignificandSize - kSignificandSize; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 int Sign() const { | 148 int Sign() const { |
149 uint64_t d64 = AsUint64(); | 149 uint64_t d64 = AsUint64(); |
150 return (d64 & kSignMask) == 0 ? 1 : -1; | 150 return (d64 & kSignMask) == 0 ? 1 : -1; |
151 } | 151 } |
152 | 152 |
153 // Precondition: the value encoded by this Double must be greater or equal | 153 // Precondition: the value encoded by this Double must be greater or equal |
154 // than +0.0. | 154 // than +0.0. |
155 DiyFp UpperBoundary() const { | 155 DiyFp UpperBoundary() const { |
156 ASSERT(Sign() > 0); | 156 DCHECK_GT(Sign(), 0); |
157 return DiyFp(Significand() * 2 + 1, Exponent() - 1); | 157 return DiyFp(Significand() * 2 + 1, Exponent() - 1); |
158 } | 158 } |
159 | 159 |
160 // Computes the two boundaries of this. | 160 // Computes the two boundaries of this. |
161 // The bigger boundary (m_plus) is normalized. The lower boundary has the same | 161 // The bigger boundary (m_plus) is normalized. The lower boundary has the same |
162 // exponent as m_plus. | 162 // exponent as m_plus. |
163 // Precondition: the value encoded by this Double must be greater than 0. | 163 // Precondition: the value encoded by this Double must be greater than 0. |
164 void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const { | 164 void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const { |
165 ASSERT(value() > 0.0); | 165 DCHECK_GT(value(), 0.0); |
166 DiyFp v = this->AsDiyFp(); | 166 DiyFp v = this->AsDiyFp(); |
167 bool significand_is_zero = (v.f() == kHiddenBit); | 167 bool significand_is_zero = (v.f() == kHiddenBit); |
168 DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1)); | 168 DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1)); |
169 DiyFp m_minus; | 169 DiyFp m_minus; |
170 if (significand_is_zero && v.e() != kDenormalExponent) { | 170 if (significand_is_zero && v.e() != kDenormalExponent) { |
171 // The boundary is closer. Think of v = 1000e10 and v- = 9999e9. | 171 // The boundary is closer. Think of v = 1000e10 and v- = 9999e9. |
172 // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but | 172 // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but |
173 // at a distance of 1e8. | 173 // at a distance of 1e8. |
174 // The only exception is for the smallest normal: the largest denormal is | 174 // The only exception is for the smallest normal: the largest denormal is |
175 // at the same distance as its successor. | 175 // at the same distance as its successor. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return (significand & kSignificandMask) | | 240 return (significand & kSignificandMask) | |
241 (biased_exponent << kPhysicalSignificandSize); | 241 (biased_exponent << kPhysicalSignificandSize); |
242 } | 242 } |
243 }; | 243 }; |
244 | 244 |
245 } // namespace double_conversion | 245 } // namespace double_conversion |
246 | 246 |
247 } // namespace WTF | 247 } // namespace WTF |
248 | 248 |
249 #endif // DOUBLE_CONVERSION_DOUBLE_H_ | 249 #endif // DOUBLE_CONVERSION_DOUBLE_H_ |
OLD | NEW |