Decimal arithmetic, with example code

Tim Peters tim.one at comcast.net
Sat Oct 5 13:09:21 EDT 2002


[Bengt Richter]
> I understand. OTOH, if you had an installer that automatically
> tested safety using the available infrastructure, the large majority
> of platforms might be able to get optimized speed, where the fallback
> would be a guaranteed platform-independent implementation... Which
> gets you to the question of what safety means.

To me, it gets more to the question of what speed means <wink>.  People
mucking with dollars and cents generally do two things a lot:  I/O
conversions, and additions.  Addition is fastest if using (conceptually
scaled) ints internally, but I/O conversions fastest if using a BCD-like
scheme internally.  Fancy float alternatives are slower for both.

For this reason, I don't think it's worth investing any brainpower in
figuring out just how much you can do in binary fp and still get the same
results.  As an intellectual exercise in the analysis and control of fp
rounding errors, it's a good one, but the more-or-less obvious all-integer
and all-BCD approaches are obviously correct instead of (at best) delicately
correct, and also run faster for most appropriate apps.

win/win-vs-lose/lose-it's-not-a-hard-choice<wink>-ly y'rs  - tim





More information about the Python-list mailing list