Search code examples
pythonpython-3.xscientific-notation

Python uses the scientific notation to show that 5.26E-325 is 0,but 5.26E-324 is 5e-324,why?


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?

Solution

  • 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.