[ 
https://issues.apache.org/jira/browse/MATH-251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12693542#action_12693542
 ] 

Benjamin Croizet commented on MATH-251:
---------------------------------------

Ok I completely agree with you :
- the _*clone()*_ method can be removed, since the class is immutable, it isn't 
necessary to keep it.
- your improvement about the double constructor makes sens
- indeed, I don't have used the 
_*MathRuntimeException.createNullPointerException*_ method, better to use it as 
the _*Fraction*_ class.
- the _*compareTo*_ method was effectively wrong, I just copied the one from 
the _*Fraction*_ class without thinking :-)

I've just noticed a small improvement which could be done about the 
_*getReducedFraction()*_ method :
- we can remove the _*.reduce()*_ code since the _*BigFraction(int, int)*_ do it

I see only few things to do now : 
- add some tests for new methods in the _*BigFractionTest*_ class (such as 
_*pow*_)
- add two methods in the _*FractionFormat*_ class :
{code:java}
public static String formatFraction(BigFraction f)
public StringBuffer format(BigFraction fraction, StringBuffer toAppendTo, 
FieldPosition pos)
{code}

It is ok for me, you can close this ER when you'll feel it :o)

Nice work Luc.
Thanks.

> 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.

Reply via email to