public static FloatToken int2float( IntToken term, IntToken precision, IntToken exponent, TermContext context) { return FloatToken.of( new BigFloat( term.bigIntegerValue(), new BinaryMathContext(precision.intValue(), exponent.intValue())), exponent.intValue()); }
/** * Rounds {@code term} to the specfiied precision and exponent range. * * <p>Method is undefined if either integer is less than 2 because 2 is the minimum precision and * exponent. Two exponents must be used to store zero/subnormal/infinity/nan, so 4 is the minimum * number of distinct exponents a float can have. MPFR does not support floats with 1 bit of * precision. bits of the float. */ public static FloatToken round( FloatToken term, IntToken precision, IntToken exponent, TermContext context) { if (precision.intValue() < 2 || exponent.intValue() < 2) { return null; } return FloatToken.of( term.bigFloatValue() .round(new BinaryMathContext(precision.intValue(), exponent.intValue())), exponent.intValue()); }
public static IntToken exponentBits(FloatToken term, TermContext context) { return IntToken.of(term.exponent()); }
public static IntToken exponent(FloatToken term, TermContext context) { BinaryMathContext mc = getMathContext(term); return IntToken.of(term.bigFloatValue().exponent(mc.minExponent, mc.maxExponent)); }
public static IntToken precision(FloatToken term, TermContext context) { return IntToken.of(term.bigFloatValue().precision()); }
public static FloatToken minValue( IntToken precision, IntToken exponentBits, TermContext context) { BinaryMathContext mc = new BinaryMathContext(precision.intValue(), exponentBits.intValue()); return FloatToken.of(BigFloat.minValue(mc.precision, mc.minExponent), exponentBits.intValue()); }
/** * Rounds {@code term} to an integer by truncating it. Function is only defined on ordinary * numbers (i.e. not NaN or infinity). */ public static IntToken float2int(FloatToken term, TermContext context) { return IntToken.of( term.bigFloatValue() .rint(getMathContext(term).withRoundingMode(RoundingMode.DOWN)) .toBigIntegerExact()); }
public static FloatToken root(FloatToken term1, IntToken term2, TermContext context) { return FloatToken.of( term1.bigFloatValue().root(term2.intValue(), getMathContext(term1)), term1.exponent()); }