Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

floating point - What is the range of values a float can have in Python?

What are its smallest and biggest values in python?

question from:https://stackoverflow.com/questions/1835787/what-is-the-range-of-values-a-float-can-have-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
>>> import sys
>>> sys.float_info
sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308,
min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53,
epsilon=2.2204460492503131e-16, radix=2, rounds=1)

The smallest is sys.float_info.min (2.2250738585072014e-308) and the biggest is sys.float_info.max (1.7976931348623157e+308). See documentation for other properties.

sys.float_info.min is the normalized min. You can usually get the denormalized min as sys.float_info.min * sys.float_info.epsilon. Note that such numbers are represented with a loss of precision. As expected, the denormalized min is less than the normalized min.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...