OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 141 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
142 int min_exponent, | 142 int min_exponent, |
143 int max_exponent, | 143 int max_exponent, |
144 DiyFp* power, | 144 DiyFp* power, |
145 int* decimal_exponent) { | 145 int* decimal_exponent) { |
146 int kQ = DiyFp::kSignificandSize; | 146 int kQ = DiyFp::kSignificandSize; |
147 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); | 147 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); |
148 int foo = kCachedPowersOffset; | 148 int foo = kCachedPowersOffset; |
149 int index = | 149 int index = |
150 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; | 150 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; |
| 151 ASSERT(0 <= index && index < static_cast<int>(ARRAY_SIZE(kCachedPowers))); |
151 CachedPower cached_power = kCachedPowers[index]; | 152 CachedPower cached_power = kCachedPowers[index]; |
152 ASSERT(min_exponent <= cached_power.binary_exponent); | 153 ASSERT(min_exponent <= cached_power.binary_exponent); |
153 (void) max_exponent; // Mark variable as used. | 154 (void) max_exponent; // Mark variable as used. |
154 ASSERT(cached_power.binary_exponent <= max_exponent); | 155 ASSERT(cached_power.binary_exponent <= max_exponent); |
155 *decimal_exponent = cached_power.decimal_exponent; | 156 *decimal_exponent = cached_power.decimal_exponent; |
156 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 157 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
157 } | 158 } |
158 | 159 |
159 | 160 |
160 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, | 161 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, |
161 DiyFp* power, | 162 DiyFp* power, |
162 int* found_exponent) { | 163 int* found_exponent) { |
163 ASSERT(kMinDecimalExponent <= requested_exponent); | 164 ASSERT(kMinDecimalExponent <= requested_exponent); |
164 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); | 165 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); |
165 int index = | 166 int index = |
166 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; | 167 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; |
167 CachedPower cached_power = kCachedPowers[index]; | 168 CachedPower cached_power = kCachedPowers[index]; |
168 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 169 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
169 *found_exponent = cached_power.decimal_exponent; | 170 *found_exponent = cached_power.decimal_exponent; |
170 ASSERT(*found_exponent <= requested_exponent); | 171 ASSERT(*found_exponent <= requested_exponent); |
171 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); | 172 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); |
172 } | 173 } |
173 | 174 |
174 } // namespace double_conversion | 175 } // namespace double_conversion |
OLD | NEW |