Aahz email@example.com wrote:
On Tue, Aug 01, 2006, M.-A. Lemburg wrote:
You often have a need for controlled rounding when doing financial calculations or in situations where you want to compare two floats with a given accuracy, e.g. to work around rounding problems ;-)
The usual approach is to use full float accuracy throughout the calculation and then apply rounding a certain key places.
That's what Decimal() is for.
Well, maybe. There are other approaches, too, and Decimal has its problems with that. In particular, when people need precisely defined decimal rounding, they ALWAYS need fixed-point and not floating-point.
(Note that I don't care all that much about round(), but I do think we want to canonicalize Decimal() for all purposes in standard Python where people care about accuracy. Additional float features can go into NumPy.)
Really? That sounds like dogma, not science.
Decimal doesn't even help people who care about accuracy. At most (and with the reservation mentioned above), it means that you can can map external decimal formats to internal ones without loss of precision. Not a big deal, as there ARE no requirements for doing that for floating-point, and there are plenty of other solutions for fixed-point.
People who care about the accuracy of calculations prefer binary, as it is a more accurate model. That isn't a big deal, either.
Regards, Nick Maclaren, University of Cambridge Computing Service, New Museums Site, Pembroke Street, Cambridge CB2 3QH, England. Email: firstname.lastname@example.org Tel.: +44 1223 334761 Fax: +44 1223 334679