diff options
author | Victor Zverovich <victor.zverovich@gmail.com> | 2018-04-28 14:32:05 -0700 |
---|---|---|
committer | Victor Zverovich <victor.zverovich@gmail.com> | 2018-04-28 14:32:05 -0700 |
commit | dd296e1de08e512d5f308736e9f5767c7034d457 (patch) | |
tree | 6778ac12a03e6d9556059092fe396b0b0c73f3d8 /support | |
parent | 0efc8a1808892b28230a32786908bf302b1ca114 (diff) | |
download | fmtlib-dd296e1de08e512d5f308736e9f5767c7034d457.tar.gz |
Add a script to compute powers of 10
Diffstat (limited to 'support')
-rwxr-xr-x | support/compute-powers.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/support/compute-powers.py b/support/compute-powers.py new file mode 100755 index 00000000..db541be8 --- /dev/null +++ b/support/compute-powers.py @@ -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)) |