Skip to content

Commit 78e3e5b

Browse files
committed
Extend the small inverse pow5 offset table
The maximum value for the invPow5 function is 342, which means the offset table needs 342 * 2 = 684 bits or > 21 32-bit values. Add the missing values by computing them based off the full table values. Signed-off-by: Keith Packard <keithp@keithp.com>
1 parent 1264a94 commit 78e3e5b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ryu/d2s_small_table.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ static const uint64_t DOUBLE_POW5_INV_SPLIT2[15][2] = {
4141
{ 10313493231639821582u, 1313665730009899186u },
4242
{ 12701016819766672773u, 2032799256770390445u }
4343
};
44-
static const uint32_t POW5_INV_OFFSETS[19] = {
44+
static const uint32_t POW5_INV_OFFSETS[22] = {
4545
0x54544554, 0x04055545, 0x10041000, 0x00400414, 0x40010000, 0x41155555,
4646
0x00000454, 0x00010044, 0x40000000, 0x44000041, 0x50454450, 0x55550054,
4747
0x51655554, 0x40004000, 0x01000001, 0x00010500, 0x51515411, 0x05555554,
48-
0x00000000
48+
0x50411500, 0x40040000, 0x05040110, 0x00000000,
4949
};
5050

5151
static const uint64_t DOUBLE_POW5_SPLIT2[13][2] = {
@@ -173,6 +173,7 @@ static inline void double_computeInvPow5(const uint32_t i, uint64_t* const resul
173173
}
174174
// high1 | sum | low0
175175
const uint32_t delta = pow5bits(base2) - pow5bits(i);
176+
assert (i/16 < sizeof(POW5_INV_OFFSETS) / sizeof(POW5_INV_OFFSETS[0]));
176177
result[0] = shiftright128(low0, sum, delta) + 1 + ((POW5_INV_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3);
177178
result[1] = shiftright128(sum, high1, delta);
178179
}

0 commit comments

Comments
 (0)