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 |
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 "cached-powers.h" | 28 #include "cached-powers.h" |
29 | 29 |
30 #include "utils.h" | |
31 #include <stdarg.h> | |
32 #include <limits.h> | 30 #include <limits.h> |
33 #include <math.h> | 31 #include <math.h> |
| 32 #include <stdarg.h> |
| 33 #include "utils.h" |
34 | 34 |
35 namespace WTF { | 35 namespace WTF { |
36 | 36 |
37 namespace double_conversion { | 37 namespace double_conversion { |
38 | 38 |
39 struct CachedPower { | 39 struct CachedPower { |
40 uint64_t significand; | 40 uint64_t significand; |
41 int16_t binary_exponent; | 41 int16_t binary_exponent; |
42 int16_t decimal_exponent; | 42 int16_t decimal_exponent; |
43 }; | 43 }; |
44 | 44 |
45 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) | 45 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) |
46 static const CachedPower kCachedPowers[] = { | 46 static const CachedPower kCachedPowers[] = { |
47 {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348}, | 47 {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348}, |
48 {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340}, | 48 {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340}, |
49 {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332}, | 49 {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332}, |
50 {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324}, | 50 {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324}, |
51 {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316}, | 51 {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316}, |
52 {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308}, | 52 {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308}, |
53 {UINT64_2PART_C(0xab70fe17, c79ac6ca), -1060, -300}, | 53 {UINT64_2PART_C(0xab70fe17, c79ac6ca), -1060, -300}, |
54 {UINT64_2PART_C(0xff77b1fc, bebcdc4f), -1034, -292}, | 54 {UINT64_2PART_C(0xff77b1fc, bebcdc4f), -1034, -292}, |
55 {UINT64_2PART_C(0xbe5691ef, 416bd60c), -1007, -284}, | 55 {UINT64_2PART_C(0xbe5691ef, 416bd60c), -1007, -284}, |
56 {UINT64_2PART_C(0x8dd01fad, 907ffc3c), -980, -276}, | 56 {UINT64_2PART_C(0x8dd01fad, 907ffc3c), -980, -276}, |
57 {UINT64_2PART_C(0xd3515c28, 31559a83), -954, -268}, | 57 {UINT64_2PART_C(0xd3515c28, 31559a83), -954, -268}, |
58 {UINT64_2PART_C(0x9d71ac8f, ada6c9b5), -927, -260}, | 58 {UINT64_2PART_C(0x9d71ac8f, ada6c9b5), -927, -260}, |
59 {UINT64_2PART_C(0xea9c2277, 23ee8bcb), -901, -252}, | 59 {UINT64_2PART_C(0xea9c2277, 23ee8bcb), -901, -252}, |
60 {UINT64_2PART_C(0xaecc4991, 4078536d), -874, -244}, | 60 {UINT64_2PART_C(0xaecc4991, 4078536d), -874, -244}, |
61 {UINT64_2PART_C(0x823c1279, 5db6ce57), -847, -236}, | 61 {UINT64_2PART_C(0x823c1279, 5db6ce57), -847, -236}, |
62 {UINT64_2PART_C(0xc2109436, 4dfb5637), -821, -228}, | 62 {UINT64_2PART_C(0xc2109436, 4dfb5637), -821, -228}, |
63 {UINT64_2PART_C(0x9096ea6f, 3848984f), -794, -220}, | 63 {UINT64_2PART_C(0x9096ea6f, 3848984f), -794, -220}, |
64 {UINT64_2PART_C(0xd77485cb, 25823ac7), -768, -212}, | 64 {UINT64_2PART_C(0xd77485cb, 25823ac7), -768, -212}, |
65 {UINT64_2PART_C(0xa086cfcd, 97bf97f4), -741, -204}, | 65 {UINT64_2PART_C(0xa086cfcd, 97bf97f4), -741, -204}, |
66 {UINT64_2PART_C(0xef340a98, 172aace5), -715, -196}, | 66 {UINT64_2PART_C(0xef340a98, 172aace5), -715, -196}, |
67 {UINT64_2PART_C(0xb23867fb, 2a35b28e), -688, -188}, | 67 {UINT64_2PART_C(0xb23867fb, 2a35b28e), -688, -188}, |
68 {UINT64_2PART_C(0x84c8d4df, d2c63f3b), -661, -180}, | 68 {UINT64_2PART_C(0x84c8d4df, d2c63f3b), -661, -180}, |
69 {UINT64_2PART_C(0xc5dd4427, 1ad3cdba), -635, -172}, | 69 {UINT64_2PART_C(0xc5dd4427, 1ad3cdba), -635, -172}, |
70 {UINT64_2PART_C(0x936b9fce, bb25c996), -608, -164}, | 70 {UINT64_2PART_C(0x936b9fce, bb25c996), -608, -164}, |
71 {UINT64_2PART_C(0xdbac6c24, 7d62a584), -582, -156}, | 71 {UINT64_2PART_C(0xdbac6c24, 7d62a584), -582, -156}, |
72 {UINT64_2PART_C(0xa3ab6658, 0d5fdaf6), -555, -148}, | 72 {UINT64_2PART_C(0xa3ab6658, 0d5fdaf6), -555, -148}, |
73 {UINT64_2PART_C(0xf3e2f893, dec3f126), -529, -140}, | 73 {UINT64_2PART_C(0xf3e2f893, dec3f126), -529, -140}, |
74 {UINT64_2PART_C(0xb5b5ada8, aaff80b8), -502, -132}, | 74 {UINT64_2PART_C(0xb5b5ada8, aaff80b8), -502, -132}, |
75 {UINT64_2PART_C(0x87625f05, 6c7c4a8b), -475, -124}, | 75 {UINT64_2PART_C(0x87625f05, 6c7c4a8b), -475, -124}, |
76 {UINT64_2PART_C(0xc9bcff60, 34c13053), -449, -116}, | 76 {UINT64_2PART_C(0xc9bcff60, 34c13053), -449, -116}, |
77 {UINT64_2PART_C(0x964e858c, 91ba2655), -422, -108}, | 77 {UINT64_2PART_C(0x964e858c, 91ba2655), -422, -108}, |
78 {UINT64_2PART_C(0xdff97724, 70297ebd), -396, -100}, | 78 {UINT64_2PART_C(0xdff97724, 70297ebd), -396, -100}, |
79 {UINT64_2PART_C(0xa6dfbd9f, b8e5b88f), -369, -92}, | 79 {UINT64_2PART_C(0xa6dfbd9f, b8e5b88f), -369, -92}, |
80 {UINT64_2PART_C(0xf8a95fcf, 88747d94), -343, -84}, | 80 {UINT64_2PART_C(0xf8a95fcf, 88747d94), -343, -84}, |
81 {UINT64_2PART_C(0xb9447093, 8fa89bcf), -316, -76}, | 81 {UINT64_2PART_C(0xb9447093, 8fa89bcf), -316, -76}, |
82 {UINT64_2PART_C(0x8a08f0f8, bf0f156b), -289, -68}, | 82 {UINT64_2PART_C(0x8a08f0f8, bf0f156b), -289, -68}, |
83 {UINT64_2PART_C(0xcdb02555, 653131b6), -263, -60}, | 83 {UINT64_2PART_C(0xcdb02555, 653131b6), -263, -60}, |
84 {UINT64_2PART_C(0x993fe2c6, d07b7fac), -236, -52}, | 84 {UINT64_2PART_C(0x993fe2c6, d07b7fac), -236, -52}, |
85 {UINT64_2PART_C(0xe45c10c4, 2a2b3b06), -210, -44}, | 85 {UINT64_2PART_C(0xe45c10c4, 2a2b3b06), -210, -44}, |
86 {UINT64_2PART_C(0xaa242499, 697392d3), -183, -36}, | 86 {UINT64_2PART_C(0xaa242499, 697392d3), -183, -36}, |
87 {UINT64_2PART_C(0xfd87b5f2, 8300ca0e), -157, -28}, | 87 {UINT64_2PART_C(0xfd87b5f2, 8300ca0e), -157, -28}, |
88 {UINT64_2PART_C(0xbce50864, 92111aeb), -130, -20}, | 88 {UINT64_2PART_C(0xbce50864, 92111aeb), -130, -20}, |
89 {UINT64_2PART_C(0x8cbccc09, 6f5088cc), -103, -12}, | 89 {UINT64_2PART_C(0x8cbccc09, 6f5088cc), -103, -12}, |
90 {UINT64_2PART_C(0xd1b71758, e219652c), -77, -4}, | 90 {UINT64_2PART_C(0xd1b71758, e219652c), -77, -4}, |
91 {UINT64_2PART_C(0x9c400000, 00000000), -50, 4}, | 91 {UINT64_2PART_C(0x9c400000, 00000000), -50, 4}, |
92 {UINT64_2PART_C(0xe8d4a510, 00000000), -24, 12}, | 92 {UINT64_2PART_C(0xe8d4a510, 00000000), -24, 12}, |
93 {UINT64_2PART_C(0xad78ebc5, ac620000), 3, 20}, | 93 {UINT64_2PART_C(0xad78ebc5, ac620000), 3, 20}, |
94 {UINT64_2PART_C(0x813f3978, f8940984), 30, 28}, | 94 {UINT64_2PART_C(0x813f3978, f8940984), 30, 28}, |
95 {UINT64_2PART_C(0xc097ce7b, c90715b3), 56, 36}, | 95 {UINT64_2PART_C(0xc097ce7b, c90715b3), 56, 36}, |
96 {UINT64_2PART_C(0x8f7e32ce, 7bea5c70), 83, 44}, | 96 {UINT64_2PART_C(0x8f7e32ce, 7bea5c70), 83, 44}, |
97 {UINT64_2PART_C(0xd5d238a4, abe98068), 109, 52}, | 97 {UINT64_2PART_C(0xd5d238a4, abe98068), 109, 52}, |
98 {UINT64_2PART_C(0x9f4f2726, 179a2245), 136, 60}, | 98 {UINT64_2PART_C(0x9f4f2726, 179a2245), 136, 60}, |
99 {UINT64_2PART_C(0xed63a231, d4c4fb27), 162, 68}, | 99 {UINT64_2PART_C(0xed63a231, d4c4fb27), 162, 68}, |
100 {UINT64_2PART_C(0xb0de6538, 8cc8ada8), 189, 76}, | 100 {UINT64_2PART_C(0xb0de6538, 8cc8ada8), 189, 76}, |
101 {UINT64_2PART_C(0x83c7088e, 1aab65db), 216, 84}, | 101 {UINT64_2PART_C(0x83c7088e, 1aab65db), 216, 84}, |
102 {UINT64_2PART_C(0xc45d1df9, 42711d9a), 242, 92}, | 102 {UINT64_2PART_C(0xc45d1df9, 42711d9a), 242, 92}, |
103 {UINT64_2PART_C(0x924d692c, a61be758), 269, 100}, | 103 {UINT64_2PART_C(0x924d692c, a61be758), 269, 100}, |
104 {UINT64_2PART_C(0xda01ee64, 1a708dea), 295, 108}, | 104 {UINT64_2PART_C(0xda01ee64, 1a708dea), 295, 108}, |
105 {UINT64_2PART_C(0xa26da399, 9aef774a), 322, 116}, | 105 {UINT64_2PART_C(0xa26da399, 9aef774a), 322, 116}, |
106 {UINT64_2PART_C(0xf209787b, b47d6b85), 348, 124}, | 106 {UINT64_2PART_C(0xf209787b, b47d6b85), 348, 124}, |
107 {UINT64_2PART_C(0xb454e4a1, 79dd1877), 375, 132}, | 107 {UINT64_2PART_C(0xb454e4a1, 79dd1877), 375, 132}, |
108 {UINT64_2PART_C(0x865b8692, 5b9bc5c2), 402, 140}, | 108 {UINT64_2PART_C(0x865b8692, 5b9bc5c2), 402, 140}, |
109 {UINT64_2PART_C(0xc83553c5, c8965d3d), 428, 148}, | 109 {UINT64_2PART_C(0xc83553c5, c8965d3d), 428, 148}, |
110 {UINT64_2PART_C(0x952ab45c, fa97a0b3), 455, 156}, | 110 {UINT64_2PART_C(0x952ab45c, fa97a0b3), 455, 156}, |
111 {UINT64_2PART_C(0xde469fbd, 99a05fe3), 481, 164}, | 111 {UINT64_2PART_C(0xde469fbd, 99a05fe3), 481, 164}, |
112 {UINT64_2PART_C(0xa59bc234, db398c25), 508, 172}, | 112 {UINT64_2PART_C(0xa59bc234, db398c25), 508, 172}, |
113 {UINT64_2PART_C(0xf6c69a72, a3989f5c), 534, 180}, | 113 {UINT64_2PART_C(0xf6c69a72, a3989f5c), 534, 180}, |
114 {UINT64_2PART_C(0xb7dcbf53, 54e9bece), 561, 188}, | 114 {UINT64_2PART_C(0xb7dcbf53, 54e9bece), 561, 188}, |
115 {UINT64_2PART_C(0x88fcf317, f22241e2), 588, 196}, | 115 {UINT64_2PART_C(0x88fcf317, f22241e2), 588, 196}, |
116 {UINT64_2PART_C(0xcc20ce9b, d35c78a5), 614, 204}, | 116 {UINT64_2PART_C(0xcc20ce9b, d35c78a5), 614, 204}, |
117 {UINT64_2PART_C(0x98165af3, 7b2153df), 641, 212}, | 117 {UINT64_2PART_C(0x98165af3, 7b2153df), 641, 212}, |
118 {UINT64_2PART_C(0xe2a0b5dc, 971f303a), 667, 220}, | 118 {UINT64_2PART_C(0xe2a0b5dc, 971f303a), 667, 220}, |
119 {UINT64_2PART_C(0xa8d9d153, 5ce3b396), 694, 228}, | 119 {UINT64_2PART_C(0xa8d9d153, 5ce3b396), 694, 228}, |
120 {UINT64_2PART_C(0xfb9b7cd9, a4a7443c), 720, 236}, | 120 {UINT64_2PART_C(0xfb9b7cd9, a4a7443c), 720, 236}, |
121 {UINT64_2PART_C(0xbb764c4c, a7a44410), 747, 244}, | 121 {UINT64_2PART_C(0xbb764c4c, a7a44410), 747, 244}, |
122 {UINT64_2PART_C(0x8bab8eef, b6409c1a), 774, 252}, | 122 {UINT64_2PART_C(0x8bab8eef, b6409c1a), 774, 252}, |
123 {UINT64_2PART_C(0xd01fef10, a657842c), 800, 260}, | 123 {UINT64_2PART_C(0xd01fef10, a657842c), 800, 260}, |
124 {UINT64_2PART_C(0x9b10a4e5, e9913129), 827, 268}, | 124 {UINT64_2PART_C(0x9b10a4e5, e9913129), 827, 268}, |
125 {UINT64_2PART_C(0xe7109bfb, a19c0c9d), 853, 276}, | 125 {UINT64_2PART_C(0xe7109bfb, a19c0c9d), 853, 276}, |
126 {UINT64_2PART_C(0xac2820d9, 623bf429), 880, 284}, | 126 {UINT64_2PART_C(0xac2820d9, 623bf429), 880, 284}, |
127 {UINT64_2PART_C(0x80444b5e, 7aa7cf85), 907, 292}, | 127 {UINT64_2PART_C(0x80444b5e, 7aa7cf85), 907, 292}, |
128 {UINT64_2PART_C(0xbf21e440, 03acdd2d), 933, 300}, | 128 {UINT64_2PART_C(0xbf21e440, 03acdd2d), 933, 300}, |
129 {UINT64_2PART_C(0x8e679c2f, 5e44ff8f), 960, 308}, | 129 {UINT64_2PART_C(0x8e679c2f, 5e44ff8f), 960, 308}, |
130 {UINT64_2PART_C(0xd433179d, 9c8cb841), 986, 316}, | 130 {UINT64_2PART_C(0xd433179d, 9c8cb841), 986, 316}, |
131 {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324}, | 131 {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324}, |
132 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332}, | 132 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332}, |
133 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340}, | 133 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340}, |
134 }; | 134 }; |
135 static const int kCachedPowersOffset = 348; // -kCachedPowers[0].decimal_exp
onent | 135 static const int kCachedPowersOffset = |
| 136 348; // -kCachedPowers[0].decimal_exponent |
136 | 137 |
137 const int PowersOfTenCache::kDecimalExponentDistance = 8; // kCachedPowers[1
].decimal_exponent - kCachedPowers[0].decimal_exponent | 138 const int PowersOfTenCache::kDecimalExponentDistance = |
138 const int PowersOfTenCache::kMinDecimalExponent = -348; // kCachedPowers[0].
decimal_exponent | 139 8; // kCachedPowers[1].decimal_exponent - kCachedPowers[0].decimal_exponent |
139 const int PowersOfTenCache::kMaxDecimalExponent = 340; // kCachedPowers[kCac
hedPowersLength - 1].decimal_exponent | 140 const int PowersOfTenCache::kMinDecimalExponent = |
| 141 -348; // kCachedPowers[0].decimal_exponent |
| 142 const int PowersOfTenCache::kMaxDecimalExponent = |
| 143 340; // kCachedPowers[kCachedPowersLength - 1].decimal_exponent |
140 | 144 |
141 #if DCHECK_IS_ON() | 145 #if DCHECK_IS_ON() |
142 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); | 146 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); |
143 | 147 |
144 // Check that the static constants match the values in kCachedPowers. | 148 // Check that the static constants match the values in kCachedPowers. |
145 static void validateStaticConstants() { | 149 static void validateStaticConstants() { |
146 ASSERT(kCachedPowersOffset == -kCachedPowers[0].decimal_exponent); | 150 ASSERT(kCachedPowersOffset == -kCachedPowers[0].decimal_exponent); |
147 ASSERT(PowersOfTenCache::kDecimalExponentDistance == (kCachedPowers[1].d
ecimal_exponent - kCachedPowers[0].decimal_exponent)); | 151 ASSERT( |
148 ASSERT(PowersOfTenCache::kMinDecimalExponent == kCachedPowers[0].decimal
_exponent); | 152 PowersOfTenCache::kDecimalExponentDistance == |
149 ASSERT(PowersOfTenCache::kMaxDecimalExponent == kCachedPowers[kCachedPow
ersLength - 1].decimal_exponent); | 153 (kCachedPowers[1].decimal_exponent - kCachedPowers[0].decimal_exponent)); |
150 } | 154 ASSERT(PowersOfTenCache::kMinDecimalExponent == |
| 155 kCachedPowers[0].decimal_exponent); |
| 156 ASSERT(PowersOfTenCache::kMaxDecimalExponent == |
| 157 kCachedPowers[kCachedPowersLength - 1].decimal_exponent); |
| 158 } |
151 #endif | 159 #endif |
152 | 160 |
153 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 161 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
154 int min_exponent
, | 162 int min_exponent, |
155 int max_exponent
, | 163 int max_exponent, |
156 DiyFp* power, | 164 DiyFp* power, |
157 int* decimal_exp
onent) { | 165 int* decimal_exponent) { |
158 #if DCHECK_IS_ON() | 166 #if DCHECK_IS_ON() |
159 validateStaticConstants(); | 167 validateStaticConstants(); |
160 #endif | 168 #endif |
161 const int kQ = DiyFp::kSignificandSize; | 169 const int kQ = DiyFp::kSignificandSize; |
162 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); | 170 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); |
163 int foo = kCachedPowersOffset; | 171 int foo = kCachedPowersOffset; |
164 int index = | 172 int index = (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; |
165 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; | 173 ASSERT(0 <= index && index < kCachedPowersLength); |
166 ASSERT(0 <= index && index < kCachedPowersLength); | 174 CachedPower cached_power = kCachedPowers[index]; |
167 CachedPower cached_power = kCachedPowers[index]; | 175 ASSERT(min_exponent <= cached_power.binary_exponent); |
168 ASSERT(min_exponent <= cached_power.binary_exponent); | 176 ASSERT(cached_power.binary_exponent <= max_exponent); |
169 ASSERT(cached_power.binary_exponent <= max_exponent); | 177 *decimal_exponent = cached_power.decimal_exponent; |
170 *decimal_exponent = cached_power.decimal_exponent; | 178 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
171 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 179 } |
172 } | |
173 | 180 |
174 | 181 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, |
175 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone
nt, | 182 DiyFp* power, |
176 DiyFp* power, | 183 int* found_exponent) { |
177 int* found_exponent)
{ | 184 ASSERT(kMinDecimalExponent <= requested_exponent); |
178 ASSERT(kMinDecimalExponent <= requested_exponent); | 185 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); |
179 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan
ce); | |
180 #if DCHECK_IS_ON() | 186 #if DCHECK_IS_ON() |
181 validateStaticConstants(); | 187 validateStaticConstants(); |
182 #endif | 188 #endif |
183 int index = | 189 int index = |
184 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; | 190 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; |
185 CachedPower cached_power = kCachedPowers[index]; | 191 CachedPower cached_power = kCachedPowers[index]; |
186 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); | 192 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); |
187 *found_exponent = cached_power.decimal_exponent; | 193 *found_exponent = cached_power.decimal_exponent; |
188 ASSERT(*found_exponent <= requested_exponent); | 194 ASSERT(*found_exponent <= requested_exponent); |
189 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); | 195 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); |
190 } | 196 } |
191 | 197 |
192 } // namespace double_conversion | 198 } // namespace double_conversion |
193 | 199 |
194 } // namespace WTF | 200 } // namespace WTF |
OLD | NEW |