[Python-Dev] PEP239 (Rational Numbers) Reference Implementation and new issues
Chad Netzer
cnetzer at mail.arc.nasa.gov
Thu Oct 3 23:35:25 EDT 2002
My comments about 0/0 were somewhat tongue-in-cheek, so don't take them
too seriously. :)
As Tim Peters pointed out, there is often a convention in the numerical
field to declare (for the purposes of floating point calculation) that:
1.0/0.0 = Inf
0.0/0.0 = NaN
A useful question is what to do with the equivalent rational
expressions? Should the floating point conventions be followed?
Should there even be the equivalent of a NaN or Inf? Do they apply
only when memory limits, or lossy conversions, come into play?
My gut instinct is that both 1/0 and 0/0 should simply throw divide by
zero, and that NaN and Inf do not exist. If they do exist, they are
defined directly by subclasses of the rational type (and are NOT
created by any simple, defined expression, only by practical limits).
At least that should be the default; like floating point, there may be
a need to override the exception throwing behavior (for array
operations, etc.) But this complicates things, and since these are not
performance critical, I think it best to keep things simple and
consistent. Those working with large numbers of rationals may just
have to deal with the possibility of exceptions, and perhaps
precondition there data. (A compromise might be a DividedByZero
object, that is distinct from a Nan or Inf)
That said, I have little practical experience with rational types in
other languages or toolkits. Any thoughts on these ideas?
BTW. The expression/definition that always makes me shake MY head is
(0**0 == 1). Limits are amazing things...
--
Chad Netzer
cnetzer at mail.arc.nasa.gov
More information about the Python-list
mailing list