Decimal arithmatic, was Re: Python GUI app to impress the boss?
Christian Tismer
tismer at tismer.com
Tue Oct 1 22:56:06 EDT 2002
Paul Rubin wrote:
> "Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net> writes:
>
>>>What do you mean by "right"? What do you mean by "all
>>>cases"?
>>
>>The original subject is *business* arithmetic. There is no
>>choice but to use decimal arithmetic if you want your math
>>results to match good-old-fashioned pen and paper math.
>
>
> No, I'm still not convinced. Is business arithmetic well-defined
> enough that you can never do the same calculation two ways and get
> different results?
>
> Example: bunches are three for a dollar. How much do you pay if you
> buy nine bananas?
>
> Answer #1:
> price_per_banana = 1.00 / 3
> number_of_bananas = 9
> total_price = number_of_bananas * price_per_banana
> print total_price
>
> Answer #2:
> price_per_bunch = 1.00 # three bananas
> number_of_bunches = 3
> total_price = number_of_bunches * price_per_banana
> print total_price
Sorry, this is an argument I cannot accept.
A discussion about decimal or floating arithmetic
doesn't give the right to break basic rules of
numeric computation. It is a known fact that
division by a number that contains a prime factor
relatively prime to the number base produces
an error.
I would fire such a programmer in any case, whether the
error shows up in decimal math, or wether it hides
due to graceful rounding rules in floating point.
> With floating point and rounding on output, you get the same answer
> both ways.
Exercise: Find the extremes where this claim is proven wrong.
Finally I see a big advantage in decimal math:
Doing wrong numeric shows up earlier :-)
ciao - chris
--
Christian Tismer :^) <mailto:tismer at tismer.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Python-list
mailing list