OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 #include <stdarg.h> | 6 #include <stdarg.h> |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "include/v8stdint.h" | 9 #include "include/v8stdint.h" |
10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 int max_exponent, | 126 int max_exponent, |
127 DiyFp* power, | 127 DiyFp* power, |
128 int* decimal_exponent) { | 128 int* decimal_exponent) { |
129 int kQ = DiyFp::kSignificandSize; | 129 int kQ = DiyFp::kSignificandSize; |
130 // Some platforms return incorrect sign on 0 result. We can ignore that here, | 130 // Some platforms return incorrect sign on 0 result. We can ignore that here, |
131 // which means we can avoid depending on platform.h. | 131 // which means we can avoid depending on platform.h. |
132 double k = std::ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); | 132 double k = std::ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); |
133 int foo = kCachedPowersOffset; | 133 int foo = kCachedPowersOffset; |
134 int index = | 134 int index = |
135 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; | 135 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; |
136 ASSERT(0 <= index && index < kCachedPowersLength); | 136 DCHECK(0 <= index && index < kCachedPowersLength); |
137 CachedPower cached_power = kCachedPowers[index]; | 137 CachedPower cached_power = kCachedPowers[index]; |
138 ASSERT(min_exponent <= cached_power.binary_exponent); | 138 DCHECK(min_exponent <= cached_power.binary_exponent); |
139 ASSERT(cached_power.binary_exponent <= max_exponent); | 139 DCHECK(cached_power.binary_exponent <= max_exponent); |
140 *decimal_exponent = cached_power.decimal_exponent; | 140 *decimal_exponent = cached_power.decimal_exponent; |
141 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 141 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, | 145 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, |
146 DiyFp* power, | 146 DiyFp* power, |
147 int* found_exponent) { | 147 int* found_exponent) { |
148 ASSERT(kMinDecimalExponent <= requested_exponent); | 148 DCHECK(kMinDecimalExponent <= requested_exponent); |
149 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); | 149 DCHECK(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); |
150 int index = | 150 int index = |
151 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; | 151 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; |
152 CachedPower cached_power = kCachedPowers[index]; | 152 CachedPower cached_power = kCachedPowers[index]; |
153 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 153 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
154 *found_exponent = cached_power.decimal_exponent; | 154 *found_exponent = cached_power.decimal_exponent; |
155 ASSERT(*found_exponent <= requested_exponent); | 155 DCHECK(*found_exponent <= requested_exponent); |
156 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); | 156 DCHECK(requested_exponent < *found_exponent + kDecimalExponentDistance); |
157 } | 157 } |
158 | 158 |
159 } } // namespace v8::internal | 159 } } // namespace v8::internal |
OLD | NEW |