You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/06/20 14:14:48 UTC
DO NOT REPLY [Bug 35434] New: -
Corrections to Constructor Fraction(double)
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35434>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=35434
Summary: Corrections to Constructor Fraction(double)
Product: Commons
Version: Nightly Builds
Platform: All
OS/Version: other
Status: NEW
Severity: normal
Priority: P2
Component: Math
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: J.Weimar@tu-bs.de
The constructor for Fraction fails for doubles which are almost integer.
examples should be inserted in th etest case:
public void testConstructorDouble() {
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());
}
}
The fix for this problem is to include the following code in the constructor:
int n = 0;
boolean stop = false;
// check for (almost) integer arguments, which should not go
// to iterations.
if (Math.abs(a0 - value)<epsilon){
this.numerator = a0;
this.denominator = 1;
return;
}
do {
++n;
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org