PEP239 (Rational Numbers) Reference Implementation and new issues
Paul Boddie
paul at boddie.net
Fri Oct 4 03:45:39 EDT 2002
"Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net> wrote in message news:<mailman.1033615625.14473.python-list at python.org>...
>
> But I don't want to see rationals if I haven't asked for
> them.
[...]
> but would it hurt so much to say
>
> 1/3R
>
> instead?
How about the use of specially formed rational literals using the
underscore notation, which I'm sure exists in various other systems?
For example:
1_3
The standard operators would produce rational results from rational
inputs:
1_3 + 2 == 7_3
1_3 - 2 == -5_3
1_3 / 2 == 1_6
1_3 * 2 == 2_3
Use of floating point values in such operations would either produce
errors:
1_3 + 2.5 -> TypeError
Or they could coerce the result to floating point (with the usual
consequences):
1_3 + 2.5 -> 1.0 / 3.0 + 2.5 == 2.8333333333333335
One would then need to define operators or functions to produce
rationals from other types:
rational(1, 3) == 1_3
rational(1) == 1_1
rational(1.5) -> TypeError
And certain built-in functions would need changing:
int(1_3) == 0
float(1_3) -> 1.0 / 3.0 == 0.33333333333333331
I'm sure that all this has been discussed over and over again before,
though.
Paul
More information about the Python-list
mailing list