commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [lang] [math] org.apache.commons.lang.math.Fraction class
Date Sun, 30 May 2004 21:54:25 GMT
> > The existing add(), subtract(), and multiplyBy() and divide() code (as
far
> > as I can tell) all returned reduced fractions, so existing arithmetic
code
> > should largely be unaffected.  The primary visible difference is that
> > before
> >  Fraction.getFraction(2,4).equals(Fraction.getFraction(1,2))==false
> > and now it would be true.
> > I view the previous behavior as "surprising" and a bug, honestly.
>
> I am inclined to agree here; though I am not sure exactly what the
> original author's intention was and how people may be using the class now.
>    The fact that the arithmetic operations return reduced fractions makes
> it hard to understand why equals works the way that it does now.

What about getNumerator()/getDenominator() - won't these change if 2/4 is
held differently? I believe that we need to preserve the 2/4 concept
distinct from 1/2, at least in the [lang] version.


> One thing that we might want to consider, given the magnitude of the
> changes, is deprecating this in [lang] and moving it to [math].  That way,
> among other things, the (better) continued fraction implementation in
> [math] could be used in getFraction(double).  The improved gcd and checked
> integer arithmetic methods in the patch might also make good additions to
> o.a.c.math.MathUtils.

The [lang] code needs to work and be reliable. However I suspect that a
[math] version and [lang] version may be appropriate with slightly different
semantics.

Stephen


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message