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
            Priority: Minor
             Fix For: 2.0


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.

Reply via email to