Class BigIntegerToRationalDecorator
java.lang.Object
com.singularsys.extensions.field.implementations.FieldDecorator
com.singularsys.extensions.field.implementations.BigIntegerToRationalDecorator
- All Implemented Interfaces:
FieldI,IntegerConvertor,Serializable
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 used 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
use
RationalField 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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertInput(Object in) Converts BigInteger, Integer, Long and Short to Rational.convertOutput(Object out) If possible convert Rationals to BigIntegers.
-
Constructor Details
-
BigIntegerToRationalDecorator
-
BigIntegerToRationalDecorator
-
-
Method Details
-
convertInput
Converts BigInteger, Integer, Long and Short to Rational.- Specified by:
convertInputin classFieldDecorator- Parameters:
in-- Returns:
- If appropriate convert
into a different type, otherwise returnin.
-
convertOutput
If possible convert Rationals to BigIntegers.- Specified by:
convertOutputin classFieldDecorator- Parameters:
out-- Returns:
- If appropriate convert
outto a different type, otherwise returnout.
-