* Converts the number to that type, and assigns it to the given position in the
* array associated with that type.
*/
private void promote( Number arg, int position, Type type2 ) {
if ( type2.isLessThan( Type.BIGINTEGER ) ) {
throw new InternalReasonerException( "Cannot promote to anything less than BigInteger" );
}
Type type1 = findType( arg );
if ( type2 == Type.DOUBLE ) {
doubleArgs[position] = arg.doubleValue();
}
else if ( type2 == Type.FLOAT ) {
floatArgs[position] = arg.floatValue();
}
else if ( type2 == Type.BIGDECIMAL ) {
if ( type1 == Type.BIGDECIMAL ) {
decimalArgs[position] = (BigDecimal) arg;
}
else if ( type1 == Type.BIGINTEGER ) {
decimalArgs[position] = new BigDecimal( (BigInteger) arg, 0, MathContext.DECIMAL128 );
}
else if ( type1.isLessThan( Type.BIGINTEGER ) ) {
decimalArgs[position] = new BigDecimal( arg.longValue(), MathContext.DECIMAL128 );
}
else {
throw new InternalReasonerException( "Do not know how to convert " + type1 + " to BigDecimal.");
}
}
else if ( type2 == Type.BIGINTEGER ) {
if ( type1 == Type.BIGINTEGER ) {
bigIntArgs[position] = (BigInteger) arg;
}
else if ( type1.isLessThan( Type.BIGINTEGER ) ) {
bigIntArgs[position] = new BigDecimal( arg.longValue(), MathContext.DECIMAL128 ).toBigInteger();
} else {
throw new InternalReasonerException( "Do not know how to convert " + type1 + " to BigInteger.");
}
} else {
throw new InternalReasonerException( "Do not know how to promote numbers to type " + type2 );
}
}