BigFloat implements Comparable<BigFloat>, Serializable { public static Context context(int precision) { return new Context(new MathContext(precision)); } private  BigFloat(BigDecimal value, Context context); static Context context(int precision); static Context context(MathContext mathContext); BigFloat add(BigFloat x); BigFloat add(BigDecimal x); BigFloat add(int x); BigFloat add(long x); BigFloat add(double x); BigFloat subtract(BigFloat x); BigFloat subtract(BigDecimal x); BigFloat subtract(int x); BigFloat subtract(long x); BigFloat subtract(double x); BigFloat multiply(BigFloat x); BigFloat multiply(BigDecimal x); BigFloat multiply(int x); BigFloat multiply(long x); BigFloat multiply(double x); BigFloat divide(BigFloat x); BigFloat divide(BigDecimal x); BigFloat divide(int x); BigFloat divide(long x); BigFloat divide(double x); BigFloat remainder(BigFloat x); BigFloat remainder(BigDecimal x); BigFloat remainder(int x); BigFloat remainder(long x); BigFloat remainder(double x); BigFloat pow(BigFloat y); BigFloat pow(BigDecimal y); BigFloat pow(int y); BigFloat pow(long y); BigFloat pow(double y); BigFloat root(BigFloat y); BigFloat root(BigDecimal y); BigFloat root(int y); BigFloat root(long y); BigFloat root(double y); @Override int hashCode(); @Override boolean equals(Object obj); int signum(); boolean isNegative(); boolean isZero(); boolean isPositive(); @Override int compareTo(BigFloat other); boolean isEqual(BigFloat other); boolean isLessThan(BigFloat other); boolean isGreaterThan(BigFloat other); boolean isLessThanOrEqual(BigFloat other); boolean isGreaterThanOrEqual(BigFloat other); boolean isIntValue(); boolean isDoubleValue(); BigFloat getMantissa(); BigFloat getExponent(); BigFloat getIntegralPart(); BigFloat getFractionalPart(); Context getContext(); BigDecimal toBigDecimal(); double toDouble(); long toLong(); int toInt(); @Override String toString(); boolean isNaN(); boolean isInfinity(); static BigFloat negate(BigFloat x); static BigFloat abs(BigFloat x); static BigFloat max(BigFloat value1, BigFloat value2); static BigFloat max(BigFloat value1, BigFloat... values); static BigFloat min(BigFloat value1, BigFloat value2); static BigFloat min(BigFloat value1, BigFloat... values); static BigFloat log(BigFloat x); static BigFloat log2(BigFloat x); static BigFloat log10(BigFloat x); static BigFloat exp(BigFloat x); static BigFloat sqrt(BigFloat x); static BigFloat pow(BigFloat x, BigFloat y); static BigFloat root(BigFloat x, BigFloat y); static BigFloat sin(BigFloat x); static BigFloat cos(BigFloat x); static BigFloat tan(BigFloat x); static BigFloat cot(BigFloat x); static BigFloat asin(BigFloat x); static BigFloat acos(BigFloat x); static BigFloat atan(BigFloat x); static BigFloat acot(BigFloat x); static BigFloat sinh(BigFloat x); static BigFloat cosh(BigFloat x); static BigFloat tanh(BigFloat x); static BigFloat coth(BigFloat x); static BigFloat asinh(BigFloat x); static BigFloat acosh(BigFloat x); static BigFloat atanh(BigFloat x); static BigFloat acoth(BigFloat x); static boolean isBetween(BigFloat min, BigFloat max, BigFloat value); static final BigFloat NaN; static final BigFloat POSITIVE_INFINITY; static final BigFloat NEGATIVE_INFINITY; }
@Test public void testContext() { MathContext mathContext = new MathContext(20); Context context = context(mathContext); assertEquals(mathContext, context.getMathContext()); assertEquals(mathContext.getPrecision(), context.getPrecision()); assertEquals(mathContext.getRoundingMode(), context.getRoundingMode()); assertEquals(1000, context(1000).getPrecision()); assertEquals(context, context(mathContext)); assertEquals(context.hashCode(), context(mathContext).hashCode()); assertEquals(context.toString(), context(mathContext).toString()); assertNotEquals(context, null); assertNotEquals(context, "string"); }
@Test public void testFactorial() { Context context = context(MathContext.DECIMAL32); assertEquals(context.valueOf(720), context.factorial(6)); }
@Test public void testSerialize() { try { Context context = BigFloat.context(32); BigFloat testVal = context.valueOf(Integer.MAX_VALUE); BigFloat negTestVal = context.valueOf(Integer.MIN_VALUE); BigFloat POS_INF = POSITIVE_INFINITY; BigFloat NEG_INF = NEGATIVE_INFINITY; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(testVal); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); ByteArrayOutputStream INFbaos = new ByteArrayOutputStream(); ObjectOutputStream INFoos = new ObjectOutputStream(INFbaos); INFoos.writeObject(POS_INF); ByteArrayInputStream INFbais = new ByteArrayInputStream(INFbaos.toByteArray()); ObjectInputStream INFois = new ObjectInputStream(INFbais); ByteArrayOutputStream nbaos = new ByteArrayOutputStream(); ObjectOutputStream noos = new ObjectOutputStream(nbaos); noos.writeObject(negTestVal); ByteArrayInputStream nbais = new ByteArrayInputStream(nbaos.toByteArray()); ObjectInputStream nois = new ObjectInputStream(nbais); ByteArrayOutputStream NINFbaos = new ByteArrayOutputStream(); ObjectOutputStream NINFoos = new ObjectOutputStream(NINFbaos); NINFoos.writeObject(NEG_INF); ByteArrayInputStream NINFbais = new ByteArrayInputStream(NINFbaos.toByteArray()); ObjectInputStream NINFois = new ObjectInputStream(NINFbais); assertEquals(testVal, ois.readObject()); assertEquals(negTestVal, nois.readObject()); assertEquals(POS_INF, INFois.readObject()); assertEquals(NEG_INF, NINFois.readObject()); } catch (Exception e) { e.printStackTrace(); } }