Class BigIntegerToRationalDecorator
- java.lang.Object
-
- com.singularsys.extensions.field.implementations.FieldDecorator
-
- com.singularsys.extensions.field.implementations.BigIntegerToRationalDecorator
-
- All Implemented Interfaces:
FieldI
,java.io.Serializable
public class BigIntegerToRationalDecorator extends FieldDecorator
Converts BigIntegers, Long, Integer and Short to Rationals on input. Optionally on output if the rational number represents an integer then convert it back to a BigInteger.This should be use to wrap an
RationalField
. Problems will occur if combined with an IntegerField as the IntegerField will convert a fraction like "5/2" into integer division giving a result of the integer 2. Instead to mix Rationals and BigIntegers useRationalField rf = new RationalField(); BigIntegerToRationalDecorator ird = new BigIntegerToRationalDecorator(rf,true); FieldOperatorTable fot = new FieldOperatorTable(ird); BigIntegerNumberFactory inf = new BigIntegerNumberFactory(); Jep jep = new Jep(fot,inf);
which performing all calculations in rationals and converts results to BigInteger if possible.To mix Integers and Rationals use
RationalField rf = new RationalField(); BigIntegerToRationalDecorator ird = new BigIntegerToRationalDecorator(rf,true); IntegerToBigIntegerDecorator ibid = new IntegerToBigIntegerDecorator(ird,true); FieldOperatorTable fot = new FieldOperatorTable(ibid); IntegerNumberFactory inf = new IntegerNumberFactory(); Jep jep = new Jep(fot,inf);
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BigIntegerToRationalDecorator(FieldI field)
BigIntegerToRationalDecorator(FieldI field, boolean simplifyResults)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
convertInput(java.lang.Object in)
Converts BigInteger, Integer, Long and Short to Rational.java.lang.Object
convertOutput(java.lang.Object out)
If possible convert Rationals to BigIntegers.
-
-
-
Method Detail
-
convertInput
public java.lang.Object convertInput(java.lang.Object in) throws EvaluationException
Converts BigInteger, Integer, Long and Short to Rational.- Specified by:
convertInput
in classFieldDecorator
- Returns:
- If appropriate convert
in
to a different type, otherwise returnin
. - Throws:
EvaluationException
-
convertOutput
public java.lang.Object convertOutput(java.lang.Object out) throws EvaluationException
If possible convert Rationals to BigIntegers.- Specified by:
convertOutput
in classFieldDecorator
- Returns:
- If appropriate convert
out
to a different type, otherwise returnout
. - Throws:
EvaluationException
-
-