fn computeInvPow5(i: u32) [2]u64 i: u32737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753 fn computeInvPow5(i: u32) [2]u64 {
const base = (i + FLOAT64_POW5_TABLE_SIZE - 1) / FLOAT64_POW5_TABLE_SIZE;
const base2 = base * FLOAT64_POW5_TABLE_SIZE;
const mul = &FLOAT64_POW5_INV_SPLIT2[base]; // 1 / 5^base2
if (i == base2) {
return .{ mul[0], mul[1] };
} else {
const offset = base2 - i;
const m = FLOAT64_POW5_TABLE[offset]; // 5^offset
const b0 = @as(u128, m) * (mul[0] - 1);
const b2 = @as(u128, m) * mul[1]; // 1/5^base2 * 5^offset = 1/5^(base2-offset) = 1/5^i
const delta: u7 = @intCast(pow5Bits(base2) - pow5Bits(i));
const shift: u5 = @intCast((i % 16) << 1);
const shifted_sum = ((b0 >> delta) + (b2 << (64 - delta))) + 1 + ((FLOAT64_POW5_INV_OFFSETS[i / 16] >> shift) & 3);
return .{ @truncate(shifted_sum), @truncate(shifted_sum >> 64) };
}
}