Changed Fraction(double) to correctly handle near-integral arguments.
PR # 35434 Submitted by: Jörg Weimar git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@201813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d062702366
commit
a5c011a640
|
@ -73,6 +73,14 @@ public class Fraction extends Number implements Comparable {
|
|||
{
|
||||
double r0 = value;
|
||||
int a0 = (int)Math.floor(r0);
|
||||
|
||||
// check for (almost) integer arguments, which should not go
|
||||
// to iterations.
|
||||
if (Math.abs(a0 - value) < epsilon) {
|
||||
this.numerator = a0;
|
||||
this.denominator = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
int p0 = 1;
|
||||
int q0 = 0;
|
||||
|
|
|
@ -53,6 +53,14 @@ public class FractionTest extends TestCase {
|
|||
} catch (ArithmeticException ex) {
|
||||
// success
|
||||
}
|
||||
try {
|
||||
assertFraction(0, 1, new Fraction(0.00000000000001));
|
||||
assertFraction(2, 5, new Fraction(0.40000000000001));
|
||||
assertFraction(15, 1, new Fraction(15.0000000000001));
|
||||
|
||||
} catch (ConvergenceException ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testCompareTo() {
|
||||
|
|
|
@ -39,14 +39,17 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<body>
|
||||
<release version="1.1" date="In Development"
|
||||
description="Jakarta Commons Math 1.1 - Development">
|
||||
<action dev="psteitz" type="fix" issue="32663" due-to="Mary Ellen Foster">
|
||||
Added factories for TTest, ChiSquareTest and TestUtils class with
|
||||
static methods to create instances and execute tests.
|
||||
<action dev="psteitz" type="update" issue="35434" due-to="Jörg Weimar">
|
||||
Changed Fraction(double) to correctly handle near-integral arguments.
|
||||
</action>
|
||||
<action dev="psteitz" type="update" issue="35431" due-to="Jörg Weimar">
|
||||
Changed lcm to throw ArithmeticException (instead of returning bogus
|
||||
value) if the result is too large to store as an integer.
|
||||
</action>
|
||||
<action dev="psteitz" type="fix" issue="32663" due-to="Mary Ellen Foster">
|
||||
Added factories for TTest, ChiSquareTest and TestUtils class with
|
||||
static methods to create instances and execute tests.
|
||||
</action>
|
||||
<action dev="psteitz" type="update" issue="35042" due-to="Paul Field">
|
||||
Eliminated repeated endpoint function evalutations in BrentSolver, SecantSolver.
|
||||
</action>
|
||||
|
|
Loading…
Reference in New Issue