commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luc Maisonobe (JIRA)" <j...@apache.org>
Subject [jira] Updated: (MATH-251) Improve the Fraction class to avoid overflow problems and increase features
Date Sat, 28 Mar 2009 18:34:50 GMT

     [ https://issues.apache.org/jira/browse/MATH-251?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Luc Maisonobe updated MATH-251:
-------------------------------

    Assignee: Luc Maisonobe

The patch has been checked in the subversion repository as of r759543.

Some changes have been made.
The class has been renamed BigFraction.
Some exception handling have been simplified (no special triggering of NullPointerException
when the following code would trigger one automatically)
Some parts have been simplified.
The constructor from a double without any convergence parameters have been completely change,
including its semantic! Since the numerator and denominator are unlimited, it seemed better
to do an exact conversion for any regular double (i.e. all numbers except Double.NaN, Double.NEGATIVE_INFINITY
and Double.POSITIVE_INFINITY).
An error in the comparator has been fixed: it considered BigFraction instanes to be equal
when they were close enough, i.e. when they differ after the 16th digit approximately. This
is even wrong when numerator and denominators are integers, for example 1068966896 / 340262731
and 411557987 / 131002976 evaluate to the same double (roughly PI) but are different fractions.
The denominator and numerator are now final, ensuring the instances are immutable. Some defensive
copying have therefore being removed.
The test coverage have been improved.

I'm not sure if the clone method is really needed. The class is immutable, couldn't we simply
remove this method to avoid people copy everything when they can just share an instance ?

I will wait for the answer to this question before closing the issue.

Thanks for the patch.


> Improve the Fraction class to avoid overflow problems and increase features
> ---------------------------------------------------------------------------
>
>                 Key: MATH-251
>                 URL: https://issues.apache.org/jira/browse/MATH-251
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 1.2
>         Environment: java version "1.6.0_12"
> Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
> Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
> Windows XP
> Eclipse Ganymede 3.4.1
>            Reporter: Benjamin Croizet
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 2.0
>
>         Attachments: NewFraction.zip
>
>
> Hello everybody,
> I've improved and extended the _*Fraction*_ class for my personal needs, but it could
be nice to incorporate it within the _commons-math_ library., either by modifying the current
_*Fraction*_ class, or by creating a new class which could be called _*AdvancedFraction*_
or something like that. I've tried to keep all features from the original _*Fraction*_ class.
> {color:green}New features :{color}
> * I needed to avoid overflow problem. As a result, I've changed numerator and denominator
to _*BigInteger*_ and all associated methods / constructors.
> * I've also added other methods and static fields such as :
> {code:java}
> public String toString()
> public Fraction add(int i)
> public Fraction subtract(int i)
> public Fraction multiply(int i)
> public Fraction divide(int i)
> public Fraction pow(int exponent)
> public double pow(Fraction exponent)
> public BigDecimal bigDecimalValue()
> public Fraction clone()
> public double percentageValue()
> public static Fraction ONE_HALF = new Fraction(1, 2)
> public static Fraction ONE_QUARTER = new Fraction(1, 4){code}
> * I've made sure that the original Junit test within the _*FractionTest*_ class are all
right (I've just commented the overflow tests)
> * I've made sure that checkstyle is all right without any tabs
> {color:red}Obviously, some things need to be reworked or improved :{color}
> * Some methods are still naively implemented, such as
> {code:java}
> public Fraction add(Fraction fraction)
> public Fraction subtract(Fraction fraction)
> {code} because I don't have converted the original _*private Fraction addSub(Fraction
fraction, boolean isAdd)*_ method.
> * The original _*private Fraction(double value, double epsilon, int maxDenominator, int
maxIterations)*_ constructor may use _*BigDecimal*_ instead of _*double*_. I'm not sure it
is relevant.
> * Junit tests have to be written with news methods (such as _*pow*_)
> * Some minor adaptations have to be done in the _*FractionFormat*_ class (change _*getDenominator()*_
by _*getDenominatorAsInt()*_ for instance)
> You'll find my work in the attached zip file :
> - The _*Fraction*_ and _*FractionTest*_ classes
> - The javadoc generated with public and private fields and methods (to show you a complete
overview)
> Thank you.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message