How about adding rational fraction to Python?

Lie Lie.1296 at gmail.com
Sun Mar 2 11:23:13 EST 2008


On Mar 2, 10:02 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Lie <Lie.1... at gmail.com> writes:
> > Anyway, I don't think Python should
> > work that way, because Python have a plan for numerical integration
> > which would unify all numerical types into an apparent single type,
> > which requires removal of operator's limitations.
>
> Well I think the idea is to have a hierarchy of nested numeric types,
> not a single type.

You hit the right note, but what I meant is the numeric type
unification would make it _appear_ to consist of a single numeric type
(yeah, I know it isn't actually, but what appears from outside isn't
always what's inside).

> > from __future import division
> > a = 10
> > b = 5
> > c = a / b
> > if c * b == a: print 'multiplication is inverse of division'
>
> Try with a=7, b=25

They should still compare true, but they don't. The reason why they
don't is because of float's finite precision, which is not exactly
what we're talking here since it doesn't change the fact that
multiplication and division are inverse of each other. One way to
handle this situation is to do an epsilon aware comparison (as should
be done with any comparison involving floats), but I don't do it cause
my intention is to clarify the real problem that multiplication is
indeed inverse of division and I want to avoid obscuring that with the
epsilon comparison.



More information about the Python-list mailing list