OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const int PowersOfTenCache::kMaxDecimalExponent = 340; | 145 const int PowersOfTenCache::kMaxDecimalExponent = 340; |
146 | 146 |
147 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 147 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
148 int min_exponent, | 148 int min_exponent, |
149 int max_exponent, | 149 int max_exponent, |
150 DiyFp* power, | 150 DiyFp* power, |
151 int* decimal_exponent) { | 151 int* decimal_exponent) { |
152 int kQ = DiyFp::kSignificandSize; | 152 int kQ = DiyFp::kSignificandSize; |
153 // Some platforms return incorrect sign on 0 result. We can ignore that here, | 153 // Some platforms return incorrect sign on 0 result. We can ignore that here, |
154 // which means we can avoid depending on platform.h. | 154 // which means we can avoid depending on platform.h. |
155 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); | 155 double k = std::ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); |
156 int foo = kCachedPowersOffset; | 156 int foo = kCachedPowersOffset; |
157 int index = | 157 int index = |
158 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; | 158 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; |
159 ASSERT(0 <= index && index < kCachedPowersLength); | 159 ASSERT(0 <= index && index < kCachedPowersLength); |
160 CachedPower cached_power = kCachedPowers[index]; | 160 CachedPower cached_power = kCachedPowers[index]; |
161 ASSERT(min_exponent <= cached_power.binary_exponent); | 161 ASSERT(min_exponent <= cached_power.binary_exponent); |
162 ASSERT(cached_power.binary_exponent <= max_exponent); | 162 ASSERT(cached_power.binary_exponent <= max_exponent); |
163 *decimal_exponent = cached_power.decimal_exponent; | 163 *decimal_exponent = cached_power.decimal_exponent; |
164 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 164 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, | 168 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, |
169 DiyFp* power, | 169 DiyFp* power, |
170 int* found_exponent) { | 170 int* found_exponent) { |
171 ASSERT(kMinDecimalExponent <= requested_exponent); | 171 ASSERT(kMinDecimalExponent <= requested_exponent); |
172 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); | 172 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); |
173 int index = | 173 int index = |
174 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; | 174 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; |
175 CachedPower cached_power = kCachedPowers[index]; | 175 CachedPower cached_power = kCachedPowers[index]; |
176 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 176 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
177 *found_exponent = cached_power.decimal_exponent; | 177 *found_exponent = cached_power.decimal_exponent; |
178 ASSERT(*found_exponent <= requested_exponent); | 178 ASSERT(*found_exponent <= requested_exponent); |
179 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); | 179 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); |
180 } | 180 } |
181 | 181 |
182 } } // namespace v8::internal | 182 } } // namespace v8::internal |
OLD | NEW |