prePEP: Decimal data type

Samuel Kilchenmann skilchen at bluewin.ch
Sun Nov 9 19:56:54 EST 2003


"Bengt Richter" <bokr at oz.net> schrieb im Newsbeitrag
news:bojrg5$vim$0 at 216.39.172.122...
>
> Following is an exact decimal/<somewhat>rational module hack that
> implements rounding when the .round() method is called.
> This is not too elegant, but it might make
> an interesting toy to cross-check results with.

Thanks a lot for this interesting toy!

some results seem a little bit strange to me, eg.:

Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from exactdec import ED
>>> ED('0.95',1)
ED('9..0')
>>> ED('0.995',2)
ED('99..0')
>>> ED('0.9995',3)
ED('99.9.0')
>>> ED('0.99995',4)
ED('99.99.0')
>>> ED('0.999995',5)
ED('99.999.0')
>>> ED('0.9999995',6)
ED('1.0')
>>>

its probably due to the line:
        ret.num //= (ret.den*10**psh)
in your rounding code and the fact that:
>>> 1 // 0.1
9.0
>>> 10 // 0.01
999.0
>>> 100 // 0.001
99999.0
>>> 1000 // 0.0001
9999999.0
>>> 10000 // 0.00001
999999999.0
>>> 100000 // 0.000001
100000000000.0





More information about the Python-list mailing list