[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-user
Subject: Re: math3.fraction.Fraction :: overflow exception with maxDenominator
From: luc <luc () spaceroots ! org>
Date: 2013-06-23 6:55:35
Message-ID: aa9fd47ac915769a6a50880f54153cbb () spaceroots ! org
[Download RAW message or body]
Hi Allison,
Le 2013-06-20 12:54, Allison, Timothy B. a écrit :
> I'm getting an overflow exception when I try to create a fraction
> with a maxDenominator from a double that is very close to a simple
> fraction. For example:
>
> double d = 0.5000000001;
> Fraction f = new Fraction(d, 10);
>
> According to https://issues.apache.org/jira/browse/MATH-181, there
> are two separate use cases: one for a user-specified epsilon (in
> which
> case maxDenominator is set to Integer.MAX_VALUE), and one for a
> user-specified maxDenominator (in which case, epsilon is set to
> 0.0f).
>
> If I add a check for whether q2 is > maxDenominator before the
> potential overflow throw, I no longer have the problem mentioned
> above. The overflow throw, I think, is designed for the user-defined
> epsilon use case, not the maxDenominator use case.
>
> Is this a reasonable fix? Should I submit a patch?
Yes, this is a reasonable fix. Could you open a JIRA issue and attache
your patch
including a test case?
Thanks a lot
Luc
>
> double r1 = 1.0 / (r0 - a0);
> long a1 = (long)FastMath.floor(r1);
> p2 = (a1 * p1) + p0;
> q2 = (a1 * q1) + q0;
>
> if (q2 >= maxDenominator){
> this.numerator = (int) p1;
> this.denominator = (int) q1;
> return;
> }
> if ((FastMath.abs(p2) > overflow) || (FastMath.abs(q2) >
> overflow)) {
> throw new FractionConversionException(value, p2, q2);
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic