| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 {V8_2PART_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, | 127 {V8_2PART_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, |
| 128 {V8_2PART_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, | 128 {V8_2PART_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, |
| 129 {V8_2PART_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, | 129 {V8_2PART_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, |
| 130 {V8_2PART_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, | 130 {V8_2PART_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, |
| 131 {V8_2PART_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, | 131 {V8_2PART_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, |
| 132 {V8_2PART_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, | 132 {V8_2PART_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, |
| 133 {V8_2PART_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, | 133 {V8_2PART_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); | 136 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); |
| 137 static const int kCachedPowersOffset = -kCachedPowers[0].decimal_exponent; | 137 static const int kCachedPowersOffset = 348; // -1 * the first decimal_exponent. |
| 138 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) | 138 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) |
| 139 const int PowersOfTenCache::kDecimalExponentDistance = | 139 // Difference between the decimal exponents in the table above. |
| 140 kCachedPowers[1].decimal_exponent - kCachedPowers[0].decimal_exponent; | 140 const int PowersOfTenCache::kDecimalExponentDistance = 8; |
| 141 const int PowersOfTenCache::kMinDecimalExponent = | 141 const int PowersOfTenCache::kMinDecimalExponent = -348; |
| 142 kCachedPowers[0].decimal_exponent; | 142 const int PowersOfTenCache::kMaxDecimalExponent = 340; |
| 143 const int PowersOfTenCache::kMaxDecimalExponent = | |
| 144 kCachedPowers[kCachedPowersLength - 1].decimal_exponent; | |
| 145 | 143 |
| 146 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 144 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
| 147 int min_exponent, | 145 int min_exponent, |
| 148 int max_exponent, | 146 int max_exponent, |
| 149 DiyFp* power, | 147 DiyFp* power, |
| 150 int* decimal_exponent) { | 148 int* decimal_exponent) { |
| 151 int kQ = DiyFp::kSignificandSize; | 149 int kQ = DiyFp::kSignificandSize; |
| 152 // Some platforms return incorrect sign on 0 result. We can ignore that here, | 150 // Some platforms return incorrect sign on 0 result. We can ignore that here, |
| 153 // which means we can avoid depending on platform.h. | 151 // which means we can avoid depending on platform.h. |
| 154 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); | 152 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 172 int index = | 170 int index = |
| 173 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; | 171 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; |
| 174 CachedPower cached_power = kCachedPowers[index]; | 172 CachedPower cached_power = kCachedPowers[index]; |
| 175 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 173 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
| 176 *found_exponent = cached_power.decimal_exponent; | 174 *found_exponent = cached_power.decimal_exponent; |
| 177 ASSERT(*found_exponent <= requested_exponent); | 175 ASSERT(*found_exponent <= requested_exponent); |
| 178 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); | 176 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); |
| 179 } | 177 } |
| 180 | 178 |
| 181 } } // namespace v8::internal | 179 } } // namespace v8::internal |
| OLD | NEW |