Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the smallest number which can be represented in python?

What is the smallest number which can be represented in python?

I have seen as small as 2.05623357236e-296 but can there be any smaller?

like image 208
poppyseeds Avatar asked Oct 14 '15 16:10

poppyseeds


People also ask

What is the smallest float in Python?

The smallest is sys. float_info. min (2.2250738585072014e-308) and the biggest is sys. float_info.

How do you find the lowest number in a list in Python?

You can find the smallest number of a list in Python using min() function, sort() function or for loop.

How do you find the smallest of 3 numbers in Python?

Program ExplanationGet three inputs num1, num2 and num3 from user using input() methods. Check whether num1 is smaller than num2 and num3 using if statement, if it is true print num1 is smallest using print() method. Else, num2 or num3 is smallest. So check whether num2 is smaller than num3 using elseif statement.


2 Answers

Check out sys.float_info

>>> import sys
>>> sys.float_info 
sys.float_info(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.220446049250313e-16, radix=2, rounds=1)

From the docs

min       DBL_MIN      minimum positive normalized float 
min_exp   DBL_MIN_EXP  minimum integer e such that radix**(e-1) is a normalized float

On my system it is mentioned as min=2.2250738585072014e-308

like image 185
Bhargav Rao Avatar answered Jan 22 '23 20:01

Bhargav Rao


Check sys.float_info.min. Note that this is the minimum normalized value; the minimum denormalized value may be smaller but numerical accuracy will suffer.

With usual 64-bit floating-point numbers, the normalized min is approximately 2.2e-308. The denormalized min can be much less, down to 4.94e-324:

>>> 5e-324
4.9406564584124654e-324

It is also worth pointing out that the decimal module's Decimal type can represent arbitrarily small numbers, limited only by available memory.

like image 24
nneonneo Avatar answered Jan 22 '23 21:01

nneonneo