How about adding rational fraction to Python?

Jeff Schwab jeff at schwabcenter.com
Sun Mar 2 15:32:57 EST 2008


Paul Rubin wrote:
> I can live with int/int=float but
> find it sloppy and would be happier if int/int always threw an error
> (convert explicitly if you want a particular type result).

Better yet, how hard would it be to define an otherwise int-like type 
that did not define a non-flooring division operator?  Are there any 
real use cases for such a type?  Maybe a division operator could be 
defined to perform a run-time check that, for an operation n/d==q, 
n==q*d; else, throw an exception.  Code written to support duck-typed 
integers should work with such a UDT "out of the box."



More information about the Python-list mailing list