[Python-Dev] Expert floats

Andrew Koenig ark-mlist at att.net
Wed Mar 31 15:59:12 EST 2004


>>> import Decimal 
>>> d1 = Decimal.Decimal('1E50') 
>>> d2 = Decimal.Decimal('1E-50') 
>>> d1 + d2 
Decimal( (0, (1, 0, 0, 0, 0, 0, 0, 0, 0), 42L) ) 
>>> d1 + d2 == d1 
True 
>>> Decimal.getcontext().prec = 1000 
>>> d1 + d2 == d1 
False 
>>> d1 + d2 
Decimal( (0, (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1), -50L) )


Very nice!




More information about the Python-Dev mailing list