]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/fmt/support/compute-powers.py
2 # Compute 10 ** exp with exp in the range [min_exponent, max_exponent] and print
3 # normalized (with most-significant bit equal to 1) significands in hexadecimal.
5 from __future__
import print_function
17 for i
, exp
in enumerate(range(min_exponent
, max_exponent
+ 1, step
)):
19 n
= 10 ** exp
if exp
>= 0 else 2 ** exp_offset
/ 10 ** -exp
20 k
= significand_size
+ 1
21 # Convert to binary and round.
22 binary
= '{:b}'.format(n
)
23 result
.f
= (int('{:0<{}}'.format(binary
[:k
], k
), 2) + 1) / 2
24 result
.e
= len(binary
) - (exp_offset
if exp
< 0 else 0) - significand_size
28 actual
= result
.f
* 10 ** exp_offset10
30 actual
*= 2 ** result
.e
32 for j
in range(-result
.e
):
34 expected
= 10 ** (exp_offset10
+ exp
)
35 precision
= len('{}'.format(expected
)) - len('{}'.format(actual
- expected
))
37 print('low precision:', precision
)
40 print('Significands:', end
='')
41 for i
, fp
in enumerate(powers
):
44 print(' {:0<#16x}'.format(fp
.f
, ), end
=',')
46 print('\n\nExponents:', end
='')
47 for i
, fp
in enumerate(powers
):
50 print(' {:5}'.format(fp
.e
), end
=',')
52 print('\n\nMax exponent difference:',
53 max([x
.e
- powers
[i
- 1].e
for i
, x
in enumerate(powers
)][1:]))