You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
352 B
Python
11 lines
352 B
Python
5 years ago
|
import math
|
||
|
|
||
|
print('{:^7} {:^8} {:^17}'.format('Mantissa', 'Exponent', 'Floating point value'))
|
||
|
print('{:-^8} {:-^8} {:-^20}'.format('', '', ''))
|
||
|
|
||
|
for m, e in [ (0.7, -3),
|
||
|
(0.3, 0),
|
||
|
(0.5, 3),
|
||
|
]:
|
||
|
x = math.ldexp(m, e)
|
||
|
print('{:7.2f} {:7d} {:7.2f}'.format(m, e, x))
|