Exponential Notation and integers

Batista, Facundo FBatista at uniFON.com.ar
Fri Nov 19 07:32:31 EST 2004


[Timothy Fitz]

#- Why are all numberical literals in exponential notation floats? To me
#- it is counter-intuitive for 1e3 to behave so fundamentally different
#- from 1000.

Use Decimal. Decimal(1000) and Decimal("1e3") will behave equally.


#- >>> long(1e100)
#- 1000000000000000015902891109759918046836080856394528138978132
#- 7557747838772170381060813469985856815104L
#- >>> 1e20 == 10 ** 20 + 8192
#- True
#- >>> long(1e23) == 10 ** 23
#- False

>>> from decimal import *
>>> getcontext().prec = 110
>>> Decimal("1e100")
Decimal("1E+100")
>>> Decimal("1e100") + 1
Decimal("1000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000001")
>>> Decimal("1e100") == 10 ** 100
True

.	Facundo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041119/74deadfd/attachment.html>


More information about the Python-list mailing list