fast_float/script/analysis.py
Anders Dalvander b9793e1cd4 update scripts
* fixed version updates in release script
* formatted Python scripts with `black` - The uncompromising code formatter (https://black.readthedocs.io/)
* f-string all the things
2024-11-23 11:24:39 +01:00

39 lines
715 B
Python

import sys
from math import floor
def log2(x):
"""returns ceil(log2(x)))"""
y = 0
while (1 << y) < x:
y = y + 1
return y
for q in range(1, 17 + 1):
d = 5 ** q
b = 127 + log2(d)
t = 2 ** b
c = t // d + 1
assert c < 2 ** 128
assert c >= 2 ** 127
K = 2 ** 127
if not (c * K * d <= (K + 1) * t):
print(q)
top = floor(t / (c * d - t))
sys.exit(-1)
for q in range(18, 344 + 1):
d = 5 ** q
b = 64 + 2 * log2(d)
t = 2 ** b
c = t // d + 1
assert c > 2 ** (64 + log2(d))
K = 2 ** 64
if not (c * K * d <= (K + 1) * t):
print(q)
top = floor(t / (c * d - t))
sys.exit(-1)
print("all good")