Details

Type: Improvement

Status: Closed

Priority: Minor

Resolution: Fixed

Affects Version/s: 1.2

Fix Version/s: 2.0

Labels:None

Environment:
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12b04)
Java HotSpot(TM) Client VM (build 11.2b01, mixed mode, sharing)Windows XP
Eclipse Ganymede 3.4.1
Description
Hello everybody,
I've improved and extended the Fraction class for my personal needs, but it could be nice to incorporate it within the commonsmath 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.
New features :
 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 :
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)
 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
Obviously, some things need to be reworked or improved :
 Some methods are still naively implemented, such as
public Fraction add(Fraction fraction) public Fraction subtract(Fraction fraction)
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.
Attachments
Issue Links
 is duplicated by

LANG663 org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy
 Closed