Math errors in python
Bengt Richter
bokr at oz.net
Sun Sep 19 21:41:06 EDT 2004
On 20 Sep 2004 00:35:33 GMT, bokr at oz.net (Bengt Richter) wrote:
[...]
>
>If you add a small Decimal delta repeatedly, will it get rounded away like the floating point
>version, or will accuracy get promoted, or what? Sorry, I haven't read the docs yet ;-/
>
I needn't have used 1e-300 to get the effect -- 1e-16 is relatively small enough:
>>> acc = 1.0
>>> for i in xrange(100): acc += 1e-16
...
>>> acc
1.0
>>> ED(acc, 'all')
ED('1')
>>> ecc = ED(1)
>>> for i in xrange(100): ecc += ED('1e-16')
...
>>> ecc
ED('1.00000000000001')
Regards,
Bengt Richter
More information about the Python-list
mailing list