[Python-ideas] Python Float Update

Jim Witschey jim.witschey at gmail.com
Mon Jun 1 07:19:26 CEST 2015

On Sun, May 31, 2015 at 11:37 PM,  <random832 at fastmail.us> wrote:

> I'd worry about unbounded complexity. For rationals, unlike integers,
> values don't have to be large for their bignum representation to be
> large.

I'd expect rational representations to be reasonably small until a
value was operated on many times, in which case you're using more
space, but representing the result very precisely. It's a tradeoff,
but with a small cost in the common case.

I'm no expert, though -- am I not considering some case?

> how much do you like "6/5" as the repr of 1.2?

6/5 is an ugly representation of 1.2, but consider the current state of affairs:

>>> 1.2

"1.2" is imprecisely interpreted as 1.2000000476837158 * (2^0), which
is then imprecisely represented as 1.2. I recognize this is the way
we've dealt with non-integer numbers for a long time, but "1.2" =>
SomeKindOfRational(6, 5) => "6/5" is conceptually cleaner.

> Or are we going to use Fractions for integer division and Decimals
> for literals?

I had been thinking of rationals built on bignums all around, a la
Haskell. Is Fraction as it exists today up to it? I don't know.

I agree that some principled decisions would have to be made for,
e.g., interpretation by format strings.

More information about the Python-ideas mailing list