0

I use this code to test scientific notation:

a = 5.26E-324
print(a)

a = 5.26E-325
print(a)

The code result:

5e-324
0.0

Questions:

  1. Why 5.26E-325 cannot show 5e-325?
  2. Does this mean that less than E-324 is shown to be 0.0?
  3. Is there a way to show 5e-325?
akshat
  • 1,219
  • 1
  • 8
  • 24
  • There is a limit to how small (or big) a float can be. You just hit it. If you need more precision you may need to use float128... – Julien May 31 '18 at 04:25
  • Possible duplicate of [What is the range of values a float can have in Python?](https://stackoverflow.com/questions/1835787/what-is-the-range-of-values-a-float-can-have-in-python) – Julien May 31 '18 at 04:30

3 Answers3

1

You can use sys.float_info to check floatinfo settings of Python as Akash Gupta suggests.

However, it has not been changed from Py2.7 to Py3+ because the smallest representable denormalized float (larger than zero) can be calculated via min representable and floating epsilon.

Try this:

>>> 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)
>>> sys.float_info.min * sys.float_info.epsilon
5e-324

And you will find that 5e-324 comes from 2.22e-308 * 2.22e-16.

Haotian Liu
  • 886
  • 5
  • 19
0

It is most probably due to double precision factors,

Run these commands in your python console:

>>> import sys
>>> sys.float_info

In python 2.7 it used to return:

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)

It must have changed to the value you are trying in python 3.x

Hope this helps.

for more see Python double precision examples

akash
  • 587
  • 4
  • 16
0

Regarding the question if you represent 5.26E-325 in python: Yes, with the decimal module:

from decimal import Decimal
>>> Decimal("5e-324")
Decimal('5E-324')
>>> Decimal("5e-325")
Decimal('5E-325')
>>> Decimal("5e-100000")
Decimal('5E-100000')
>>> Decimal("5e-100000") + Decimal("5e-100000")
Decimal('1.0E-99999')

The decimal module has (after my knowledge) no limit in the exponents, but like the float in precision. But the precision shouldn't be a problem, because you can set is to a really high number.

The other question where answered in the post below quite good.

MegaIng
  • 7,361
  • 1
  • 22
  • 35