mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 06:21:00 +00:00
Add a script to compute powers of 10
This commit is contained in:
parent
0efc8a1808
commit
dd296e1de0
16
support/compute-powers.py
Executable file
16
support/compute-powers.py
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# Compute 10 ** exp with exp in the range [min_exponent, max_exponent] and print
|
||||||
|
# normalized (with most-significant bit equal to 1) significands in hexadecimal.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
min_exponent = -348
|
||||||
|
max_exponent = 340
|
||||||
|
step = 8
|
||||||
|
significand_size = 64
|
||||||
|
for exp in range(min_exponent, max_exponent + 1, step):
|
||||||
|
n = 10 ** exp if exp >= 0 else 2 ** 2000 / 10 ** -exp
|
||||||
|
k = significand_size + 1
|
||||||
|
# Convert to binary and round.
|
||||||
|
n = (int('{:0<{}b}'.format(n, k)[:k], 2) + 1) / 2
|
||||||
|
print('{:0<#16x}ull'.format(n))
|
Loading…
Reference in New Issue
Block a user