Why not FP for Money?

phansen peter at engcorp.com
Tue Sep 21 09:15:20 EDT 2004


Carlos Ribeiro wrote:
> On 21 Sep 2004 00:25:25 -0700, Chris Barker <barkmann at gmail.com> wrote:
>>If you were to use FP, you could have your IEEE 754 hardware do the
>>rounding for you, and get better performance to boot. 
> ...
> There is another potential problem: I think that the biggest benefits
> of the IEEE754 hardware would come with complex operations that are
> directly supported by the hardware. For simple tasks that make the
> bulk of money-handling code -- sums and multiplications -- integer
> based code is probably as fast or faster, even with all the checks and
> the scaling.

This is a good point, Carlos.  Although I don't know the speed
of current floating point hardware versus the integer opcodes,
it was certainly the case in the past that, while the floating
point hardware would give you a performance boost for floating
point math, *it was still slower than the CPU at integer math*.

Even if it doesn't now (which seems unlikely), choosing a path
that has greater performance but which has inherent problems
is a case of premature optimization of the worst kind...

-Peter



More information about the Python-list mailing list