How about adding rational fraction to Python?

Jeff Schwab jeff at schwabcenter.com
Sat Feb 16 13:40:50 EST 2008


Lie wrote:
> Would all these problems with floating points be a rational reason to
> add rational numbers support in Python or Py3k? (pun not intended)
> 
> I agree, there are some numbers that is rationals can't represent
> (like pi, phi, e) but these rounding problems also exist in floating
> points, and rational numbers wouldn't be so easily fooled by something
> like 1 / 3 * 3, and 1/10 (computer) is exactly 0.1 (human). The first
> problem with rational is that to get an infinite precision rational,
> the language would have to have an infinite length integers, which
> Python have given us. The second problem with rationals is to keep
> rationals in its most simple, trivial form. This can be solved with a
> good GCD algorithm, which can also be a nice addition to Python's math
> library.

http://www.python.org/dev/peps/pep-0239/



More information about the Python-list mailing list