FileDocCategorySizeDatePackage
FractionExample.javaAPI DocExample1897Wed May 18 09:39:00 BST 2005com.discursive.jccook.lang.math

FractionExample

public class FractionExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		Fraction numer1 = Fraction.getFraction( 3, 4 );
		Fraction numer2 = Fraction.getFraction( 51, 3509 );
	
		Fraction numerator = numer1.multiplyBy( numer2 );
		Fraction denominator = Fraction.getFraction( 41, 59 );
	
		Fraction result = numerator.divideBy( denominator );
	
		System.out.println( "Expression as Fraction: " + result.reduce().toString() );
		System.out.println( "Expression as double: " + result.doubleValue() );
		
		Fraction test1 = Fraction.getFraction( 1, 2 );
		Fraction test2 = Fraction.getFraction( 2, 4 );
		
		System.out.println( "1/2 equals 2/4: " + test1.equals( test2 ) );
		
		double value = Fraction.getFraction( 10000, 100000 ).pow( 6 ).doubleValue();
		double reduced = Fraction.getFraction( 10000, 100000 ).reduce().pow( 6 ).doubleValue();
		
		System.out.println( "Fraction to pow 6 without reduction: " + value );
	    System.out.println( "Fraction to pow 6 with reduction: " + reduced );