return ((BigDecimal) n).toBigIntegerExact();
} catch( ArithmeticException e ) {
throw new IllegalArgumentException( e );
}
case RATIONAL:
Rational r = (Rational) n;
if( compare( 1, r.getDenominator() ) != 0 ) {
r = Rational.simplify( r );
if( compare( 1, r.getDenominator() ) != 0 )
throw new IllegalArgumentException();
}
return bigInteger( r.getNumerator() );
default:
throw new IllegalArgumentException();
}
case BIG_DECIMAL:
switch ( in ) {
case BYTE:
case SHORT:
case INTEGER:
case LONG:
return BigDecimal.valueOf( n.longValue() );
case BIG_INTEGER:
return new BigDecimal( (BigInteger) n );
case BIG_DECIMAL:
return n;
default:
}
case RATIONAL:
switch ( in ) {
case BYTE:
case SHORT:
case INTEGER:
case LONG:
case BIG_INTEGER:
return new Rational( n, 1 );
case BIG_DECIMAL:
final BigDecimal d = (BigDecimal) n;
Number num = d.unscaledValue();
int scale = d.scale();
Number denom = BigInteger.TEN.pow( scale );
return new Rational( num, denom );
case RATIONAL:
return n;
default:
}
default: