[Edu-sig] RE: Rationals

John Posner jjposner@snet.net
Fri, 11 Oct 2002 14:52:33 -0400


Hi --

  >> > This conflicts with the current redefinition of div such
  >> > that int/int --> float, meaning code currently being redone
  >> > to match  2.2 will have to be redone again.
  >> 
  >> Um, in 2.2, 1/2 is still 0, unless you use python -Qnew. :-)

Was the "int/int --> float" decision made before the "rational" numeric
type was being considered? A few years/releases down the road, if int's
and float's and rational's are all in common usage, the decision to make
int/int yield a float may be as perplexing (to some people) as "3/2
yields the integer 1" is perplexing now (to some people).

I like this point of Kirby's:

   >> Sometimes people *want* floats from ints, so the compromise
   >> of making at least one int a rat, in order to get a rat,
   >> seems worth making (to me).

Could Python officially support multiple "numeric modes"? They could be
called with various flavors of "-Q" or some other command-line option:

* "python -Qsci" --> scientific mode: the result of some (or all?)
numeric operations that yield a real number are automatically cast to
the "float" type. This would include:

  1 + 2
  1 / 2
  1 * 2
  3 / 2

More radically, even this expression might yield a float in "scientific
mode":

  42


The list of numeric modes would include "rational" (where 3/2 yields
3/2r) and "integer" (where 3/2 yields 1).

(Actually, I'd rather see 3/2 raise an exception in "integer mode",
since the set of integers is not closed with respect to division -- kind
of like dividing by zero. And what the heck -- for elementary school
kids, there could be a "natural number mode", where the expression "3 -
5" would raise an exception.)

-John

--
John Posner
jjposner@snet.net