Comment on PEP-0238

Emile van Sebille emile at fenx.com
Wed Jul 11 20:34:58 EDT 2001


I've written a module that takes a few steps in the direction I'd like to
see things go, but even if that's not in the cards I'll probably use it
anyway.  It works like Tim's FixedPoint, but uses precision in a slightly
different way.  When run as __main__, it imports FixedPoint to compare
results as it tests.  Overall, this feels more like what I had in mind.

Anyway, a sample session follows.  If anyone is interested in testing/using
this, e-mail me and I'll send you back a copy.


Emile van Sebille
emile at fenx.com

>>> import BNum
>>> bn = Bnum.Bnum
>>> a = bn(1.111)
>>> a
1.11
>>> BNum.PRECISION = 6
>>> a = bn(1.111)
>>> a
1.111000
>>> a * a * a * a
1.523548
>>> b = 1.111
>>> b ** 4
1.5235483310410001
>>> BNum.PRECISION = 12
>>> a * a * a * a
1.523548331041
>>> BNum.PRECISION = 18
>>> a * a * a * a
1.523548331041000000
>>>
>>> a / 1.234
0.900324149108589951
>>> a -.346
0.765000000000000000
>>> a
1.111000000000000000
>>> a - 1.23456
-0.123560000000000000
>>> a - 1.234567890
-0.123567890000000000
>>> a - 1.234567890123456789
-0.123567890120000000
>>> a - '1.234567890123456789'
TypeError: object can't be converted to long
>>> a - bn('1.234567890123456789')
-0.123567890123456789





More information about the Python-list mailing list