| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
package org.mozilla.javascript.v8dtoa; |
| 32 |
|
| 33 |
public class CachedPowers { |
| 34 |
|
| 35 |
|
| 36 |
static final double kD_1_LOG2_10 = 0.30102999566398114; |
| 37 |
|
| 38 |
static class CachedPower { |
| 39 |
long significand; |
| 40 |
short binaryExponent; |
| 41 |
short decimalExponent; |
| 42 |
|
| 43 |
CachedPower(long significand, short binaryExponent, short decimalExponent) { |
| 44 |
this.significand = significand; |
| 45 |
this.binaryExponent = binaryExponent; |
| 46 |
this.decimalExponent = decimalExponent; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
static int getCachedPower(int e, int alpha, int gamma, DiyFp c_mk) { |
| 52 |
int kQ = DiyFp.kSignificandSize; |
| 53 |
double k = Math.ceil((alpha - e + kQ - 1) * kD_1_LOG2_10); |
| 54 |
int index = (GRISU_CACHE_OFFSET + (int)k - 1) / CACHED_POWERS_SPACING + 1; |
| 55 |
CachedPower cachedPower = CACHED_POWERS[index]; |
| 56 |
|
| 57 |
c_mk.setF(cachedPower.significand); |
| 58 |
c_mk.setE(cachedPower.binaryExponent); |
| 59 |
assert((alpha <= c_mk.e() + e) && (c_mk.e() + e <= gamma)); |
| 60 |
return cachedPower.decimalExponent; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static final int CACHED_POWERS_SPACING = 8; |
| 69 |
|
| 70 |
static final CachedPower[] CACHED_POWERS = { |
| 71 |
new CachedPower(0xe61acf033d1a45dfL, (short)-1087, (short)-308), |
| 72 |
new CachedPower(0xab70fe17c79ac6caL, (short)-1060, (short)-300), |
| 73 |
new CachedPower(0xff77b1fcbebcdc4fL, (short)-1034, (short)-292), |
| 74 |
new CachedPower(0xbe5691ef416bd60cL, (short)-1007, (short)-284), |
| 75 |
new CachedPower(0x8dd01fad907ffc3cL, (short)-980, (short)-276), |
| 76 |
new CachedPower(0xd3515c2831559a83L, (short)-954, (short)-268), |
| 77 |
new CachedPower(0x9d71ac8fada6c9b5L, (short)-927, (short)-260), |
| 78 |
new CachedPower(0xea9c227723ee8bcbL, (short)-901, (short)-252), |
| 79 |
new CachedPower(0xaecc49914078536dL, (short)-874, (short)-244), |
| 80 |
new CachedPower(0x823c12795db6ce57L, (short)-847, (short)-236), |
| 81 |
new CachedPower(0xc21094364dfb5637L, (short)-821, (short)-228), |
| 82 |
new CachedPower(0x9096ea6f3848984fL, (short)-794, (short)-220), |
| 83 |
new CachedPower(0xd77485cb25823ac7L, (short)-768, (short)-212), |
| 84 |
new CachedPower(0xa086cfcd97bf97f4L, (short)-741, (short)-204), |
| 85 |
new CachedPower(0xef340a98172aace5L, (short)-715, (short)-196), |
| 86 |
new CachedPower(0xb23867fb2a35b28eL, (short)-688, (short)-188), |
| 87 |
new CachedPower(0x84c8d4dfd2c63f3bL, (short)-661, (short)-180), |
| 88 |
new CachedPower(0xc5dd44271ad3cdbaL, (short)-635, (short)-172), |
| 89 |
new CachedPower(0x936b9fcebb25c996L, (short)-608, (short)-164), |
| 90 |
new CachedPower(0xdbac6c247d62a584L, (short)-582, (short)-156), |
| 91 |
new CachedPower(0xa3ab66580d5fdaf6L, (short)-555, (short)-148), |
| 92 |
new CachedPower(0xf3e2f893dec3f126L, (short)-529, (short)-140), |
| 93 |
new CachedPower(0xb5b5ada8aaff80b8L, (short)-502, (short)-132), |
| 94 |
new CachedPower(0x87625f056c7c4a8bL, (short)-475, (short)-124), |
| 95 |
new CachedPower(0xc9bcff6034c13053L, (short)-449, (short)-116), |
| 96 |
new CachedPower(0x964e858c91ba2655L, (short)-422, (short)-108), |
| 97 |
new CachedPower(0xdff9772470297ebdL, (short)-396, (short)-100), |
| 98 |
new CachedPower(0xa6dfbd9fb8e5b88fL, (short)-369, (short)-92), |
| 99 |
new CachedPower(0xf8a95fcf88747d94L, (short)-343, (short)-84), |
| 100 |
new CachedPower(0xb94470938fa89bcfL, (short)-316, (short)-76), |
| 101 |
new CachedPower(0x8a08f0f8bf0f156bL, (short)-289, (short)-68), |
| 102 |
new CachedPower(0xcdb02555653131b6L, (short)-263, (short)-60), |
| 103 |
new CachedPower(0x993fe2c6d07b7facL, (short)-236, (short)-52), |
| 104 |
new CachedPower(0xe45c10c42a2b3b06L, (short)-210, (short)-44), |
| 105 |
new CachedPower(0xaa242499697392d3L, (short)-183, (short)-36), |
| 106 |
new CachedPower(0xfd87b5f28300ca0eL, (short)-157, (short)-28), |
| 107 |
new CachedPower(0xbce5086492111aebL, (short)-130, (short)-20), |
| 108 |
new CachedPower(0x8cbccc096f5088ccL, (short)-103, (short)-12), |
| 109 |
new CachedPower(0xd1b71758e219652cL, (short)-77, (short)-4), |
| 110 |
new CachedPower(0x9c40000000000000L, (short)-50, (short)4), |
| 111 |
new CachedPower(0xe8d4a51000000000L, (short)-24, (short)12), |
| 112 |
new CachedPower(0xad78ebc5ac620000L, (short)3, (short)20), |
| 113 |
new CachedPower(0x813f3978f8940984L, (short)30, (short)28), |
| 114 |
new CachedPower(0xc097ce7bc90715b3L, (short)56, (short)36), |
| 115 |
new CachedPower(0x8f7e32ce7bea5c70L, (short)83, (short)44), |
| 116 |
new CachedPower(0xd5d238a4abe98068L, (short)109, (short)52), |
| 117 |
new CachedPower(0x9f4f2726179a2245L, (short)136, (short)60), |
| 118 |
new CachedPower(0xed63a231d4c4fb27L, (short)162, (short)68), |
| 119 |
new CachedPower(0xb0de65388cc8ada8L, (short)189, (short)76), |
| 120 |
new CachedPower(0x83c7088e1aab65dbL, (short)216, (short)84), |
| 121 |
new CachedPower(0xc45d1df942711d9aL, (short)242, (short)92), |
| 122 |
new CachedPower(0x924d692ca61be758L, (short)269, (short)100), |
| 123 |
new CachedPower(0xda01ee641a708deaL, (short)295, (short)108), |
| 124 |
new CachedPower(0xa26da3999aef774aL, (short)322, (short)116), |
| 125 |
new CachedPower(0xf209787bb47d6b85L, (short)348, (short)124), |
| 126 |
new CachedPower(0xb454e4a179dd1877L, (short)375, (short)132), |
| 127 |
new CachedPower(0x865b86925b9bc5c2L, (short)402, (short)140), |
| 128 |
new CachedPower(0xc83553c5c8965d3dL, (short)428, (short)148), |
| 129 |
new CachedPower(0x952ab45cfa97a0b3L, (short)455, (short)156), |
| 130 |
new CachedPower(0xde469fbd99a05fe3L, (short)481, (short)164), |
| 131 |
new CachedPower(0xa59bc234db398c25L, (short)508, (short)172), |
| 132 |
new CachedPower(0xf6c69a72a3989f5cL, (short)534, (short)180), |
| 133 |
new CachedPower(0xb7dcbf5354e9beceL, (short)561, (short)188), |
| 134 |
new CachedPower(0x88fcf317f22241e2L, (short)588, (short)196), |
| 135 |
new CachedPower(0xcc20ce9bd35c78a5L, (short)614, (short)204), |
| 136 |
new CachedPower(0x98165af37b2153dfL, (short)641, (short)212), |
| 137 |
new CachedPower(0xe2a0b5dc971f303aL, (short)667, (short)220), |
| 138 |
new CachedPower(0xa8d9d1535ce3b396L, (short)694, (short)228), |
| 139 |
new CachedPower(0xfb9b7cd9a4a7443cL, (short)720, (short)236), |
| 140 |
new CachedPower(0xbb764c4ca7a44410L, (short)747, (short)244), |
| 141 |
new CachedPower(0x8bab8eefb6409c1aL, (short)774, (short)252), |
| 142 |
new CachedPower(0xd01fef10a657842cL, (short)800, (short)260), |
| 143 |
new CachedPower(0x9b10a4e5e9913129L, (short)827, (short)268), |
| 144 |
new CachedPower(0xe7109bfba19c0c9dL, (short)853, (short)276), |
| 145 |
new CachedPower(0xac2820d9623bf429L, (short)880, (short)284), |
| 146 |
new CachedPower(0x80444b5e7aa7cf85L, (short)907, (short)292), |
| 147 |
new CachedPower(0xbf21e44003acdd2dL, (short)933, (short)300), |
| 148 |
new CachedPower(0x8e679c2f5e44ff8fL, (short)960, (short)308), |
| 149 |
new CachedPower(0xd433179d9c8cb841L, (short)986, (short)316), |
| 150 |
new CachedPower(0x9e19db92b4e31ba9L, (short)1013, (short)324), |
| 151 |
new CachedPower(0xeb96bf6ebadf77d9L, (short)1039, (short)332), |
| 152 |
new CachedPower(0xaf87023b9bf0ee6bL, (short)1066, (short)340) |
| 153 |
}; |
| 154 |
|
| 155 |
static final int GRISU_CACHE_MAX_DISTANCE = 27; |
| 156 |
|
| 157 |
|
| 158 |
static final int GRISU_CACHE_OFFSET = 308; |
| 159 |
|
| 160 |
|
| 161 |
} |