Decimal arithmetic, was Re: Python GUI app to impress the boss?

Christian Tismer tismer at tismer.com
Wed Oct 2 16:48:23 EDT 2002


Chris Gonnerman wrote:
> ----- Original Message ----- 
> From: "Christian Tismer" <tismer at tismer.com>
> 
>>It has a better chance to be right (meaning exact) since its
>>number base is identical to the money number base.
>>Having more prime factors than (2, 5) in it would lead to
>>even more fractions being exact, but I doubt that is not
>>what they want. They want the computer think exactly as
>>wrong as they do.
> 
> 
> Huh.  You managed to back me up and bust my chops at the
> same time.

Not exactly what I intended to do, but near to it :-)

What I tried to say was that "doing it right" means to
"do it as wrong as by hand". What bankers compute by
hand is something defined (according to rules that I
never have learned...), and the requirement is IMHO
that the computer should behave exactly the same.

Nobody claims that there is *one* way to correct
errors. There are multiple ways, depending on certain
criteria which might not be compatible to each other.
Decimal math cannot minimize all possible errors,
maybe some obvious ones are treated in a more obvious
way that using float, and therefore I consider
it wrong like any other non-rational math would be.

The key is minimizing the surprize effect. Find their
requirements and implement what matches the customer's
needs, and he'll be quiet.
(This is my primary goal with my customers: convince
them that I'm not questionable for their results.
Appears to be good to use decimal in this case).

> What, exactly, is wrong with wanting math involving
> essentially decimal monetary amounts to lead to proper
> decimal rounding?  Paul keeps waving bananas in my face.

As said, dividing by 3 first and multiplying then is
like asking for rounding errors. Unless we have a ternary
base as well, this will always give problems.

My only reqason to divide early is a possible overflow
condition. Otherwise, division almost always introduces
errors, which means it should be done as late as possible,
with the dividend being as large as possible.

(On bases: Actually, the primes (2, 3, 5) would give a quite
nice numeric base. They have lots of nice properties concerning
harmony, and the multiples of the prime factors produce
numbers people consider as "nice", most of the time.
So my number base would be at least 30 :-) )

all the best - 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