public void add(Fraction fraction2) { int a = this.numerator; int b = this.denominator; int c = fraction2.getNumerator(); int d = fraction2.getDenominator(); this.numerator = (a * d) + (b * c); this.denominator = (b * d); }
public void div( final Fraction fraction ) { this.numerator *= fraction.getDenominator(); this.denominator *= fraction.getNumerator(); }
public void mul( final Fraction fraction ) { this.numerator *= fraction.getNumerator(); this.denominator *= fraction.getDenominator(); }
public void mul( final Fraction fraction ) { this.numerator *= fraction.getNumerator(); this.denominator *= fraction.getDenominator(); }
public int compareTo(Fraction frac) { int t = this.numerator * frac.getDenominator(); int f = frac.getNumerator() * this.denominator; if(t>f) return 1; if(f>t) return -1; return 0; }
public void div( final Fraction fraction ) { this.numerator *= fraction.getDenominator(); this.denominator *= fraction.getNumerator(); }
public void add(Fraction that) { int a = this.getNumerator(); int b = this.getDenominator(); int c = that.getNumerator(); int d = that.getDenominator(); this.setNumerator((a * d) + (b * c)); this.setDenominator(b * d); }
public int compareTo(Fraction frac) { // we are comparing this=a/b with frac=c/d // by multiplying both sides by bd. // If bd is positive, then a/b < c/d <=> ad < bc. // If bd is negative, then a/b < c/d <=> ad > bc. // If bd is 0, then you've got other problems (either b=0 or d=0) int d = frac.getDenominator(); long ad = (long)this.numerator * d; long bc = (long)this.denominator * frac.getNumerator(); long diff = ((long)d*this.denominator > 0) ? (ad-bc) : (bc-ad); return (diff > 0 ? 1 : (diff < 0 ? -1 : 0)); }
public static Fraction multiply(Fraction fraction, Fraction fractionTwo) { Fraction newFraction = new Fraction(fraction.getNumerator() * fractionTwo.getNumerator(), fraction.getDenominator() * fractionTwo.getDenominator()); return newFraction.reduce(); }
public Fraction multiply(Fraction fractionTwo) { Fraction newFraction = new Fraction(numerator * fractionTwo.getNumerator(), denominator * fractionTwo.getDenominator()); return newFraction.reduce(); }
String turnImproperFractionToMixedFraction(Fraction f) { int a = f.getNumerator() / f.getDenominator(); int b = f.getNumerator() % f.getDenominator(); return a != 0 ? (a + " " + b + "/" + f.getDenominator()) : (b + "/" + f.getDenominator()); }
public static Fraction add(Fraction fraction1, Fraction fraction2) { Fraction fraction3 = new Fraction(); int a = fraction1.getNumerator(); int b = fraction1.getDenominator(); int c = fraction2.getNumerator(); int d = fraction2.getDenominator(); fraction3.setNumerator((a * d) + (b * c)); fraction3.setDenominatoļr(b * d); return fraction3; }
public Fraction add(Fraction fraction1, Fraction fraction2) { Fraction fraction3 = new Fraction(); int a = fraction1.getNumerator(); int b = fraction1.getDenominator(); int c = fraction2.getNumerator(); int d = fraction2.getDenominator(); fraction3.setNumerator((a * d) + (b * c)); fraction3.setDenominator(b * d); return fraction3 ; }
int tempFracOneNum = fracOne.getNumerator() * factorOne; int factorTwo = gcd / fracTwo.getDenominator(); int tempFracTwoNum = fracTwo.getNumerator() * factorTwo;
public void testNegate() { Fraction g = new Fraction(1,3); g = g.negate(); //added "g =" assertEquals(-1, g.getNumerator()); assertEquals(3, g.getDenominator()); }
int tempGcd; int tempFactorOne; int tempFactorTwo; Fraction sum = fractions[1]; for (int i = 2; i < fractions.length - 2; i++) // we loop from 2 to fractions.length-2 because // we ignore the least and greatest values in the array // and we assigned the initial sum to the first fraction { tempGcd = gcd(sum.getDenominator(), fractions[i].getDenominator()); tempFactorOne = tempGcd / sum.getDenominator(); tempFactorTwo = tempGcd / fractions[i].getDenominator(); sum.setNumerator(tempFactorOne * sum.getNumerator() + tempFactorTwo * fractions[i].getNumerator()); // add the numerators and store as the sum sum.setDenominator(gcd); // obviously the denominator is the gcd }
private < A > NtreeImg< T, ? > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); if ( entitiesPerPixel.getNumerator() != entitiesPerPixel.getDenominator() ) throw new RuntimeException( "not implemented" ); final long[] pos = new long[ dimensions.length ]; final NtreeImg< T, ? extends A > img = new NtreeImg<>( createNtreeAccess( typeFactory, dimensions ).createInstance( pos ), // calling createInstance(pos) is necessary here, because // otherwise javac will not infer the NtreeAccess type dimensions, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
private < A > NtreeImg< T, ? > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); if ( entitiesPerPixel.getNumerator() != entitiesPerPixel.getDenominator() ) throw new RuntimeException( "not implemented" ); final long[] pos = new long[ dimensions.length ]; final NtreeImg< T, ? extends A > img = new NtreeImg<>( createNtreeAccess( typeFactory, dimensions ).createInstance( pos ), // calling createInstance(pos) is necessary here, because // otherwise javac will not infer the NtreeAccess type dimensions, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }