proposed language change to int/int==float (was: PEP0238 lament)
Lloyd Zusman
ljz at asfast.com
Sun Jul 29 21:51:14 CEST 2001
Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> writes:
> 28 Jul 2001 23:14:01 -0400, Lloyd Zusman <ljz at asfast.com> pisze:
>
>> Agreed: rationals with a fixed denominator for calculation results,
>> such as 100 in the U.S. where we have dollars and cents.
>
> No, plain rationals will suffice. No arithmetic operation except
> division introduces a denominator which represents fractional cents.
I agree that addition, subtraction, and multiplication of these
decimal "money" quantities would work with normal rationals. But
since division is also done on these data types, we have to make sure
that we're dealing with a fixed denominator during division, which is
not standard practice when using rationals.
For example:
0.59 => 59 / 100 (in the U.S., 59 cents)
0.59 / 3 => (59 / 100) / 3
With generic rationals, this would yield 59 / 300, but this is
meaningnless when dividing quantities of U.S. money.
The result would have to be ...
0.59 / 3 => (57 / 3) / 100, remainder 2 / 100
=> 19 / 100 (19 cents), remainder 2 cents
This means that we need a numeric type that handles division
differently from the way that standard rationals do it.
While rationals handle three out of these four operations just fine,
it turns out that all four of these operations are standard integer
operations. Therefore, I believe that a better choice of number
system to extend in order to represent money would be Bignums. All
that would be needed is to add implied decimal points.
And I think that Bignums would probably be faster than rationals in
the general case, as well.
> --
> __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
> \__/
> ^^ SYGNATURA ZASTÊPCZA
> QRCZAK
--
Lloyd Zusman
ljz at asfast.com
More information about the Python-list
mailing list