OLD | NEW |
1 // Copyright 2006-2008 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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include <stdarg.h> | 28 #include <stdarg.h> |
| 29 #include <math.h> |
29 #include <limits.h> | 30 #include <limits.h> |
30 | 31 |
31 #include "v8.h" | 32 #include "../include/v8stdint.h" |
32 | 33 #include "globals.h" |
| 34 #include "checks.h" |
33 #include "cached-powers.h" | 35 #include "cached-powers.h" |
34 | 36 |
35 namespace v8 { | 37 namespace v8 { |
36 namespace internal { | 38 namespace internal { |
37 | 39 |
38 struct CachedPower { | 40 struct CachedPower { |
39 uint64_t significand; | 41 uint64_t significand; |
40 int16_t binary_exponent; | 42 int16_t binary_exponent; |
41 int16_t decimal_exponent; | 43 int16_t decimal_exponent; |
42 }; | 44 }; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 kCachedPowers[0].decimal_exponent; | 142 kCachedPowers[0].decimal_exponent; |
141 const int PowersOfTenCache::kMaxDecimalExponent = | 143 const int PowersOfTenCache::kMaxDecimalExponent = |
142 kCachedPowers[kCachedPowersLength - 1].decimal_exponent; | 144 kCachedPowers[kCachedPowersLength - 1].decimal_exponent; |
143 | 145 |
144 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 146 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
145 int min_exponent, | 147 int min_exponent, |
146 int max_exponent, | 148 int max_exponent, |
147 DiyFp* power, | 149 DiyFp* power, |
148 int* decimal_exponent) { | 150 int* decimal_exponent) { |
149 int kQ = DiyFp::kSignificandSize; | 151 int kQ = DiyFp::kSignificandSize; |
150 double k = ceiling((min_exponent + kQ - 1) * kD_1_LOG2_10); | 152 // Some platforms return incorrect sign on 0 result. We can ignore that here, |
| 153 // which means we can avoid depending on platform.h. |
| 154 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); |
151 int foo = kCachedPowersOffset; | 155 int foo = kCachedPowersOffset; |
152 int index = | 156 int index = |
153 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; | 157 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; |
154 ASSERT(0 <= index && index < kCachedPowersLength); | 158 ASSERT(0 <= index && index < kCachedPowersLength); |
155 CachedPower cached_power = kCachedPowers[index]; | 159 CachedPower cached_power = kCachedPowers[index]; |
156 ASSERT(min_exponent <= cached_power.binary_exponent); | 160 ASSERT(min_exponent <= cached_power.binary_exponent); |
157 ASSERT(cached_power.binary_exponent <= max_exponent); | 161 ASSERT(cached_power.binary_exponent <= max_exponent); |
158 *decimal_exponent = cached_power.decimal_exponent; | 162 *decimal_exponent = cached_power.decimal_exponent; |
159 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 163 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
160 } | 164 } |
161 | 165 |
162 | 166 |
163 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, | 167 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, |
164 DiyFp* power, | 168 DiyFp* power, |
165 int* found_exponent) { | 169 int* found_exponent) { |
166 ASSERT(kMinDecimalExponent <= requested_exponent); | 170 ASSERT(kMinDecimalExponent <= requested_exponent); |
167 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); | 171 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); |
168 int index = | 172 int index = |
169 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; | 173 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; |
170 CachedPower cached_power = kCachedPowers[index]; | 174 CachedPower cached_power = kCachedPowers[index]; |
171 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 175 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
172 *found_exponent = cached_power.decimal_exponent; | 176 *found_exponent = cached_power.decimal_exponent; |
173 ASSERT(*found_exponent <= requested_exponent); | 177 ASSERT(*found_exponent <= requested_exponent); |
174 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); | 178 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); |
175 } | 179 } |
176 | 180 |
177 } } // namespace v8::internal | 181 } } // namespace v8::internal |
OLD | NEW |