Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Liquid Web Cloud VPS Hosting

10,567 questions

14,363 answers

573 users

How to use frexp() to get the mantissa and exponent of float in Python

1 Answer

0 votes
import math
 
print('{:^6} {:^6} {:^6}'.format('f', 'mant', 'exp'))     
print('{:-^6} {:-^6} {:-^6}'.format('', '', ''))     
 
for f in [0.1, 0.3, 0.5, 1.0, 5.0]:         
    mant, exp = math.frexp(f)         
    print('{:5.2f} {:6.2f} {:5d}'.format(f, mant, exp))



'''
run:

  f     mant   exp
------ ------ ------
 0.10   0.80    -3
 0.30   0.60    -1
 0.50   0.50     0
 1.00   0.50     1
 5.00   0.62     3

'''

 




answered Jun 30 by avibootz
...