decimal or rational (was Re: Against PEP 240)
tdelaney at avaya.com
Thu May 31 21:26:53 EDT 2001
> Non-beginners shouldn't be much of an issue -- we're all able
> to write 7.35r for rational, or 7.35f for binary floating
> point, or 7.35d for decimal floating point, or whatever other
> kind of syntax sugar is chosen for decorations. But 7.35,
> undecorated, should be interpreted in ONE way (no context
> dependencies, no options except perhaps transiently for the
> purpose of facilitating migrations, seems to be Pythonic).
> WHICH one way? Moshe, I believe, was the one specifically
> arguing for rational -- is he around maybe to comment...?
Well, I might as well propose something which will be abhorrent to everyone
Have all three representations (rational, BCD, binary FP). An unadorned
numeric literal is stored as the fastest representation which can represent
it exactly, if possible, or FP if not possible (irrational).
So for example,
1.0 will be binary FP
7.35 will be BCD
1/6.0 will be rational.
Coercion works the same way - if a result can be stored exactly by one of
the representations, it is stored as such by the fastest representation
which can be exact.
I would *hate* to write the code to implement this. However, so long as it
is transparent to the user ...
There would of course have to be a way to specify that the entire
calculation occur in one or the other representation - if I really wanted
speed, and everything to be done as binary FP, I would hate for things to be
promoted to BCD or rational automatically.
More information about the Python-list