| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 const int PowersOfTenCache::kDecimalExponentDistance = 8; // kCachedPowers[1
].decimal_exponent - kCachedPowers[0].decimal_exponent | 137 const int PowersOfTenCache::kDecimalExponentDistance = 8; // kCachedPowers[1
].decimal_exponent - kCachedPowers[0].decimal_exponent |
| 138 const int PowersOfTenCache::kMinDecimalExponent = -348; // kCachedPowers[0].
decimal_exponent | 138 const int PowersOfTenCache::kMinDecimalExponent = -348; // kCachedPowers[0].
decimal_exponent |
| 139 const int PowersOfTenCache::kMaxDecimalExponent = 340; // kCachedPowers[kCac
hedPowersLength - 1].decimal_exponent | 139 const int PowersOfTenCache::kMaxDecimalExponent = 340; // kCachedPowers[kCac
hedPowersLength - 1].decimal_exponent |
| 140 | 140 |
| 141 #if DCHECK_IS_ON() | 141 #if DCHECK_IS_ON() |
| 142 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); | 142 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); |
| 143 | 143 |
| 144 // Check that the static constants match the values in kCachedPowers. | 144 // Check that the static constants match the values in kCachedPowers. |
| 145 static void ValidateStaticConstants() { | 145 static void ValidateStaticConstants() { |
| 146 ASSERT(kCachedPowersOffset == -kCachedPowers[0].decimal_exponent); | 146 DCHECK_EQ(kCachedPowersOffset, -kCachedPowers[0].decimal_exponent); |
| 147 ASSERT(PowersOfTenCache::kDecimalExponentDistance == | 147 DCHECK_EQ(PowersOfTenCache::kDecimalExponentDistance, |
| 148 (kCachedPowers[1].decimal_exponent - | 148 (kCachedPowers[1].decimal_exponent - |
| 149 kCachedPowers[0].decimal_exponent)); | 149 kCachedPowers[0].decimal_exponent)); |
| 150 ASSERT(PowersOfTenCache::kMinDecimalExponent == | 150 DCHECK_EQ(PowersOfTenCache::kMinDecimalExponent, |
| 151 kCachedPowers[0].decimal_exponent); | 151 kCachedPowers[0].decimal_exponent); |
| 152 ASSERT(PowersOfTenCache::kMaxDecimalExponent == | 152 DCHECK_EQ(PowersOfTenCache::kMaxDecimalExponent, |
| 153 kCachedPowers[kCachedPowersLength - 1].decimal_exponent); | 153 kCachedPowers[kCachedPowersLength - 1].decimal_exponent); |
| 154 } | 154 } |
| 155 #endif | 155 #endif |
| 156 | 156 |
| 157 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 157 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
| 158 int min_exponent
, | 158 int min_exponent
, |
| 159 int max_exponent
, | 159 int max_exponent
, |
| 160 DiyFp* power, | 160 DiyFp* power, |
| 161 int* decimal_exp
onent) { | 161 int* decimal_exp
onent) { |
| 162 #if DCHECK_IS_ON() | 162 #if DCHECK_IS_ON() |
| 163 ValidateStaticConstants(); | 163 ValidateStaticConstants(); |
| 164 #endif | 164 #endif |
| 165 const int kQ = DiyFp::kSignificandSize; | 165 const int kQ = DiyFp::kSignificandSize; |
| 166 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); | 166 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); |
| 167 int foo = kCachedPowersOffset; | 167 int foo = kCachedPowersOffset; |
| 168 int index = | 168 int index = |
| 169 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; | 169 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; |
| 170 ASSERT(0 <= index && index < kCachedPowersLength); | 170 DCHECK_LE(0, index); |
| 171 #if DCHECK_IS_ON() |
| 172 DCHECK_LT(index, kCachedPowersLength); |
| 173 #endif |
| 171 CachedPower cached_power = kCachedPowers[index]; | 174 CachedPower cached_power = kCachedPowers[index]; |
| 172 ASSERT(min_exponent <= cached_power.binary_exponent); | 175 DCHECK_LE(min_exponent, cached_power.binary_exponent); |
| 173 ASSERT(cached_power.binary_exponent <= max_exponent); | 176 DCHECK_LE(cached_power.binary_exponent, max_exponent); |
| 174 *decimal_exponent = cached_power.decimal_exponent; | 177 *decimal_exponent = cached_power.decimal_exponent; |
| 175 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 178 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
| 176 } | 179 } |
| 177 | 180 |
| 178 | 181 |
| 179 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone
nt, | 182 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone
nt, |
| 180 DiyFp* power, | 183 DiyFp* power, |
| 181 int* found_exponent)
{ | 184 int* found_exponent)
{ |
| 182 ASSERT(kMinDecimalExponent <= requested_exponent); | 185 DCHECK_LE(kMinDecimalExponent, requested_exponent); |
| 183 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan
ce); | 186 DCHECK_LT(requested_exponent, kMaxDecimalExponent + kDecimalExponentDist
ance); |
| 184 #if DCHECK_IS_ON() | 187 #if DCHECK_IS_ON() |
| 185 ValidateStaticConstants(); | 188 ValidateStaticConstants(); |
| 186 #endif | 189 #endif |
| 187 int index = | 190 int index = |
| 188 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; | 191 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; |
| 189 CachedPower cached_power = kCachedPowers[index]; | 192 CachedPower cached_power = kCachedPowers[index]; |
| 190 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 193 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
| 191 *found_exponent = cached_power.decimal_exponent; | 194 *found_exponent = cached_power.decimal_exponent; |
| 192 ASSERT(*found_exponent <= requested_exponent); | 195 DCHECK_LE(*found_exponent, requested_exponent); |
| 193 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); | 196 DCHECK_LT(requested_exponent, *found_exponent + kDecimalExponentDistance
); |
| 194 } | 197 } |
| 195 | 198 |
| 196 } // namespace double_conversion | 199 } // namespace double_conversion |
| 197 | 200 |
| 198 } // namespace WTF | 201 } // namespace WTF |
| OLD | NEW |