The auther is currently working on an installer, but just dropping it into
2.3's site-packages should work, too.
Decimal as opposed to rational:
Decimal("0.9999999999999999999999999999")
Many people can cope with the inaccuracy induced by base 10 representations
and are taken by surprise by base 2 errors.
But you are right I left too much room for interpretation.
I hacked a little rational + decimal exponent representation based toy a while
back. The original post had a bug, which someone pointed out and I posted a
followup fix for, but the revised version was not posted. But I can if someone
is interested.
ED('1')
If you give it a float, it wants to know how many decimals you mean: Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:\pywk\ut\exactdec.py", line 93, in __init__
raise ValueError(
ValueError: Specify decimals for least significant digit of 10**(-decimals)
(decimals may also be specified as 'all' to capture all bits of float)
ED('0.333333333333333314829616256247390992939472198486328125')
If you give it a string literal, it takes it as accurate, but you can round it
to create a new accurate number: ED('0.333333333333333333333333333333333333333333333333333333333333')
That's an accurate number that has all zeroes to the right of those 60 3's ED('0.999999999999999999999999999999999999999999999999999999999999')
If you don't round, you get a fully accurate result" ED('1')
It's interesting to look at pi: ED('3.141592653589793115997963468544185161590576171875')
Same actual exact decimal value gets created from '3.1415926535897931'
meaning they both have the same floating point hardware representation,
but the short version decimal literal is sufficient to set all the bits right
even though it doesn't represent the fully exact value in decimal.
Economy courtesy of the Timbot I think ;-)
I don't know what the rules in Decimal are for stage-wise rounding vs keeping
accuracy, but I imagine you could get the same kind of surprises that are
available in binary from floating point, e.g.,
Floating point: 1.0
That really is exactly 1.0
Now the calculation accurately:
ED('1') ED('1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000001') ED('1.0e-298')
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 ;-/
Regards,
Bengt Richter