Against PEP 240
nperkins7 at home.com
Thu May 31 00:21:42 CEST 2001
I think there must be a better alternative to using rationals by default.
What about decimal representation. Numbers could be stored as two integers,
i.e. (base,exp), meaning (base*10^exp).
Multiplication would be very fast, just multiply bases and add exponents.
Of course, addition and subtraction would be a little harder.
Division would sort-of 'break' the system, possibly resulting in a number
that is not representable as a decimal.
Also, what about irrational numbers like pi and sqrt(2)? The rational number
type would not help much there. I don't even know how you could begin to
'store' irrationals any sort of 'guarranteed accuracy'.
Maybe the best thing would be to have some combination of:
integers, floats, decimals, rationals, ..and maybe others, with the default
for literals like '7.35' being a decimal type. This would remove the
'surprise' for most occurrences, but would have to be transparently
convertible to either floats or rationals when necessary. (I think Scheme
has a big set of number types)
On the other hand, the current system has never bothered me. I enjoy having
tiny inaccuracies hidden from me. It all depends on coming to peace with
the idea that a float is just a number that is very close to the number that
I want it to be.
More information about the Python-list