/** * Get the number of bits of exponent to use to compute the arithmetic operation. * * <p>Currently only floats with the same precision and exponent range can be used in a * calculation. Users will have to cast floating point types manually using round() if they wish. */ private static int getExponent(FloatToken term1, FloatToken term2) { if (term1.exponent() != term2.exponent()) { throw new IllegalArgumentException( "mismatch exponent: " + "first argument exponent is represented on " + term1.exponent() + " bits " + "while second argument exponent is represented on " + term2.exponent() + "bits"); } return term1.exponent(); }
public static IntToken exponentBits(FloatToken term, TermContext context) { return IntToken.of(term.exponent()); }
/** * Get the {@link BinaryMathContext} object to use to compute the arithmetic operation. Uses * {@link RoundingMode#HALF_EVEN} and the precision and exponent range of the {@link FloatToken}. */ private static BinaryMathContext getMathContext(FloatToken term) { return new BinaryMathContext(term.bigFloatValue().precision(), term.exponent()); }
public static FloatToken floor(FloatToken term, TermContext context) { return FloatToken.of( term.bigFloatValue().rint(getMathContext(term).withRoundingMode(RoundingMode.FLOOR)), term.exponent()); }
public static FloatToken atan(FloatToken term, TermContext context) { return FloatToken.of(term.bigFloatValue().atan(getMathContext(term)), term.exponent()); }
public static FloatToken unaryMinus(FloatToken term, TermContext context) { return FloatToken.of(term.bigFloatValue().negate(getMathContext(term)), term.exponent()); }
public static FloatToken root(FloatToken term1, IntToken term2, TermContext context) { return FloatToken.of( term1.bigFloatValue().root(term2.intValue(), getMathContext(term1)), term1.exponent()); }