Package jmathexpr.arithmetic.rational.impl

Examples of jmathexpr.arithmetic.rational.impl.LongRationalNumber


    }
   
    @Test(dependsOnMethods = { "testVariables" })
    public void testRationalExpressions() {
        Expression evaluated;
        RationalNumber oneHalf = new LongRationalNumber(1, 2);
        RationalNumber oneThird = new LongRationalNumber(1, 3);
        Expression sum = new Addition(oneHalf, oneThird);
       
        evaluated = sum.evaluate();
        System.out.printf("%s = %s%n", sum, evaluated);
        assertEquals(evaluated, new LongRationalNumber(5, 6));
       
        Expression difference = new Subtraction(oneHalf, oneThird);
        evaluated = difference.evaluate();
        System.out.printf("%s = %s%n", difference, evaluated);
        assertEquals(evaluated, new LongRationalNumber(1, 6));
       
        RationalNumber sixEighth = new LongRationalNumber(6, 8);
        evaluated = sixEighth.evaluate();
        System.out.printf("%s = %s%n", sixEighth, evaluated);
        assertEquals(evaluated, new LongRationalNumber(3, 4));
       
        difference = new Subtraction(new LongRationalNumber(2, 3), new LongRationalNumber(1, 6));
        evaluated = difference.evaluate();
        System.out.printf("%s = %s%n", difference, evaluated);
        assertEquals(evaluated, new LongRationalNumber(1, 2));
       
        Expression product = new Multiplication(new LongRationalNumber(2, 3), new LongRationalNumber(9, 2));
        ElementOf isNatural = new ElementOf(product, N);
        evaluated = isNatural.evaluate();
        System.out.printf("%s = %s : %s%n", product.evaluate(), isNatural, evaluated);
        assertEquals(evaluated, TruthValue.True);
       
View Full Code Here


            LongNaturalNumber rhs = (LongNaturalNumber) divisor;

            if (value % rhs.value == 0) {
                return new LongNaturalNumber(value / rhs.value);
            } else {
                return new LongRationalNumber(value, rhs.value);
            }
        } else {
            return Numbers.divide(this, divisor);
        }
    }
View Full Code Here

        }
    }

    @Override
    public RationalNumber toRational() {
        return new LongRationalNumber(value, 1);
    }
View Full Code Here

            LongIntegerNumber rhs = (LongIntegerNumber) divisor;
           
            if (value % rhs.value == 0) {
                return new LongIntegerNumber(value / rhs.value);
            } else {
                return rhs.value > 0 ? new LongRationalNumber(value, rhs.value).evaluate() :
                        new LongRationalNumber(-value, -rhs.value).evaluate();
            }
        } else {
            return Numbers.divide(this, divisor);
        }
    }
View Full Code Here

        }
    }

    @Override
    public RationalNumber toRational() {
        return new LongRationalNumber(value, 1);
    }
View Full Code Here

TOP

Related Classes of jmathexpr.arithmetic.rational.impl.LongRationalNumber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.