[Python-Dev] Re: Future division detection

Greg Ewing greg@cosc.canterbury.ac.nz
Thu, 08 Nov 2001 12:29:24 +1300 (NZDT)


com-nospam@ccraig.org (Christopher A. Craig):

> I would like
> to have an rational cast back to a integer iff (1) the denominator is 1
> and (2) future division is active.
> 
> If I don't check (2) then I get the situation that if future division
> is inactive then `(rational('1/3')*3)/5` would yield 0 instead of
> 1/5.

I think what you're asking is impossible. Remember that "future
division is active" is a compile-time, per-module notion. Some
parts of the code may be doing old-style divisions and other
parts new-style divisions. In the above example, at the time when
you do the multiplication by 3, there is no way of knowing
what sort of division might be performed on the result at
some later time, maybe in another module where the
future division option was set differently.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+