Using fractions instead of floats

andresj at
Mon Oct 1 04:04:21 CEST 2007

On Sep 30, 6:48 pm, Ben Finney <bignose+hates-s... at>
> andresj <andres.j.... at> writes:
> > The problem arises when you try to represent some number, like 0.4 in
> > a float.
> Which is really a specific case of the general problem that, for any
> given number base, some non-integer numbers cannot be exactly
> represented as fractions.

Yes. That's what I meant to say, by giving an example.

> > Secondly, what happens if I need to sum 1/3 and 0.4? I could use
> > Decimal to represent 0.4 precisely, but what about 1/3?
> What about the sum of   (pi) and  2 (sqrt(2))?

Mm... To be honest I hadn't thought of that in the moment I wrote the
last post...
But I think then, that I'll be more specific, so that my proposal only
deals with *rational numbers*, not irrationals.

> > So the solution I think is using a fraction type/class
> As explained above, a fractional-number class only shifts the "exact
> representation" problem, it doesn't solve it.

I don't understand completely what you said, but I think you are
saying that it doesn't solve the problem with irrational numbers.
Which is exactly what this proposal doesn't solve. (Mainly because I
do not know of any way of doing it in "normal" math).

(While I write this, my mind reminds me of operating with roots " 2
(sqrt(2))", which I think could be solved in another similar way,
although it has some more specific use cases... But in any case,
that's not in the scope of this proposal, as they are irrational

More information about the Python-list mailing list