Refine search
var f = new Fraction(2, 10000); console.log(f.numerator + '/' + f.denominator);
/** * Creates an {@link ArrayImg}<{@link ShortType}, {@link ShortAccess}> * using a {@link ShortAccess} passed as argument. */ final public static < A extends ShortAccess > ArrayImg< ShortType, A > shorts( final A access, final long... dim ) { final ArrayImg< ShortType, A > img = new ArrayImg<>( access, dim, new Fraction() ); final ShortType t = new ShortType( img ); img.setLinkedType( t ); return img; }
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 void mul( final Fraction fraction ) { this.numerator *= fraction.getNumerator(); this.denominator *= fraction.getDenominator(); }
public void testNegate() { Fraction g = new Fraction(1,3); g = g.negate(); //added "g =" assertEquals(-1, g.getNumerator()); assertEquals(3, g.getDenominator()); }
public AbstractNativeImg( final long[] dim, final Fraction entitiesPerPixel ) { super( dim ); this.entitiesPerPixel = entitiesPerPixel; this.numEntities = entitiesPerPixel.mulCeil( numPixels ); }
static < T extends NativeType< T > > ImgFactory< T > getImgFactory( final Dimensions targetsize, final double[][] halfkernels, final T type ) { if ( canUseArrayImgFactory( targetsize, halfkernels ) ) return new ArrayImgFactory<>( type ); final int cellSize = ( int ) Math.pow( Integer.MAX_VALUE / type.getEntitiesPerPixel().getRatio(), 1.0 / targetsize.numDimensions() ); return new CellImgFactory<>( type, cellSize ); }
public static Fraction multiply(Fraction fraction, Fraction fractionTwo) { Fraction newFraction = new Fraction(fraction.getNumerator() * fractionTwo.getNumerator(), fraction.getDenominator() * fractionTwo.getDenominator()); return newFraction.reduce(); }
public static void main(String[] args) { int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); int c = Integer.parseInt(args[2]); int d = Integer.parseInt(args[3]); Fraction f1 = new Fraction(a,b); Fraction f2 = new Fraction(c,d); int rel = f1.compareTo(f2); String relstr = "<=>"; System.out.println(a+"/"+b+" "+relstr.charAt(rel+1)+" "+c+"/"+d); }
/** * Creates an {@link ArrayImg}<{@link UnsignedLongType}, * {@link LongAccess}> using a {@link LongAccess} passed as argument. */ final public static < A extends LongAccess > ArrayImg< UnsignedLongType, A > unsignedLongs( final A access, final long... dim ) { final ArrayImg< UnsignedLongType, A > img = new ArrayImg<>( access, dim, new Fraction() ); final UnsignedLongType t = new UnsignedLongType( img ); img.setLinkedType( t ); return img; }
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 ; }
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 AbstractNativeImg( final long[] dim, final Fraction entitiesPerPixel ) { super( dim ); this.entitiesPerPixel = entitiesPerPixel; this.numEntities = entitiesPerPixel.mulCeil( numPixels ); }
/** * Create an {@link ArrayImgFactory} if an image of the requested * <code>targetSize</code> could be held in an {@link ArrayImg}. Otherwise * return a {@link CellImgFactory} with as large as possible cell size. * * @param targetSize * size of image that the factory should be able to create. * @param type * type of the factory. * @return an {@link ArrayImgFactory} or a {@link CellImgFactory}. */ public static < T extends NativeType< T > > ImgFactory< T > getArrayOrCellImgFactory( final Dimensions targetSize, final T type ) { if ( Intervals.numElements( targetSize ) <= Integer.MAX_VALUE ) return new ArrayImgFactory<>( type ); final int cellSize = ( int ) Math.pow( Integer.MAX_VALUE / type.getEntitiesPerPixel().getRatio(), 1.0 / targetSize.numDimensions() ); return new CellImgFactory<>( type, cellSize ); }
public Fraction multiply(Fraction fractionTwo) { Fraction newFraction = new Fraction(numerator * fractionTwo.getNumerator(), denominator * fractionTwo.getDenominator()); return newFraction.reduce(); }
/** * Creates an {@link ArrayImg}<{@link DoubleType}, * {@link DoubleAccess}> using a {@link DoubleAccess} passed as argument. */ final static public < A extends DoubleAccess > ArrayImg< DoubleType, A > doubles( final A access, final long... dim ) { final ArrayImg< DoubleType, A > img = new ArrayImg<>( access, dim, new Fraction() ); final DoubleType t = new DoubleType( img ); img.setLinkedType( t ); return img; }
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 }
var f = new Fraction(.003); console.log(f.numerator + '/' + f.denominator);