commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian S O'Neill" <brone...@earthlink.net>
Subject Re: [lang] Fraction.getFraction(double) uses magic numbers
Date Sun, 10 Aug 2003 23:34:06 GMT
I don't understand why the continued fraction implementation exists at all.
Why not just get the bits from the double floating point number directly
rather than introduce error? The floating point number is already a
fraction, just encoded specially.

----- Original Message ----- 
From: "Phil Steitz" <phil@steitz.com>
To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
Sent: Sunday, August 10, 2003 02:48 P
Subject: [lang] Fraction.getFraction(double) uses magic numbers


> o.a.c.l.math.Fraction includes a getFraction factory method that takes a
> double and uses continued fractions to find a fractional approximation
> of the input.  The continued fraction implementation has a hard-coded
> maximum number of iterations (25) and maximum denominator (1000).  These
> should be documented (and the ArithmeticException if maximum iterations
> is reached before convergence).  Better (IMHO) would be to add another
> version that takes these as parameters, possibly even replacing the
> current method (I think this is new in 2.0, so there would be no problem
> with backward compatability).
>
> If there are no objections, I will submit a patch that clarifies current
> behavior and adds another method that takes maximum iterations and
> maximum denominator as additional parameters.
>
> I would also like to improve the implementation, but this can wait until
> after 2.0.
>
> Phil
>
>
> ---------------------------------------------------------------------
> 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