use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class BigIntegerMathTest method testSqrtHalfUp.
// TODO
@GwtIncompatible
public void testSqrtHalfUp() {
for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
BigInteger result = BigIntegerMath.sqrt(x, HALF_UP);
BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE);
BigInteger x4 = x.shiftLeft(2);
// sqrt(x) < result + 0.5, so 4 * x < (result + 0.5)^2 * 4
// (result + 0.5)^2 * 4 = (result^2 + result)*4 + 1
assertTrue(x4.compareTo(plusHalfSquared) < 0);
BigInteger minusHalfSquared = result.pow(2).subtract(result).shiftLeft(2).add(ONE);
// sqrt(x) > result - 0.5, so 4 * x > (result - 0.5)^2 * 4
// (result - 0.5)^2 * 4 = (result^2 - result)*4 + 1
assertTrue(result.equals(ZERO) || x4.compareTo(minusHalfSquared) >= 0);
}
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class BigIntegerMathTest method testSqrtHalfEven.
// Relies on the correctness of sqrt(BigInteger, {HALF_UP,HALF_DOWN}).
// TODO
@GwtIncompatible
public void testSqrtHalfEven() {
for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
BigInteger halfEven = BigIntegerMath.sqrt(x, HALF_EVEN);
// Now figure out what rounding mode we should behave like (it depends if FLOOR was
// odd/even).
boolean floorWasOdd = BigIntegerMath.sqrt(x, FLOOR).testBit(0);
assertEquals(BigIntegerMath.sqrt(x, floorWasOdd ? HALF_UP : HALF_DOWN), halfEven);
}
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class BigIntegerMathTest method testRoundToDouble_wayTooBig.
@GwtIncompatible
public void testRoundToDouble_wayTooBig() {
BigInteger bi = BigInteger.ONE.shiftLeft(2 * Double.MAX_EXPONENT);
new RoundToDoubleTester(bi).setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN).setExpectation(Double.POSITIVE_INFINITY, UP, CEILING).roundUnnecessaryShouldThrow().test();
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class BigIntegerMathTest method testLog10HalfDown.
// TODO
@GwtIncompatible
public void testLog10HalfDown() {
for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
int result = BigIntegerMath.log10(x, HALF_DOWN);
BigInteger x2 = x.pow(2);
// x^2 <= 10^(2 * result + 1), or else we would have rounded up
assertTrue(TEN.pow(2 * result + 1).compareTo(x2) >= 0);
// x^2 > 10^(2 * result - 1), or else we would have rounded down
assertTrue(result == 0 || TEN.pow(2 * result - 1).compareTo(x2) < 0);
}
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class BigIntegerMathTest method testLog10Ceiling.
// TODO
@GwtIncompatible
public void testLog10Ceiling() {
for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
for (RoundingMode mode : asList(CEILING, UP)) {
int result = BigIntegerMath.log10(x, mode);
assertTrue(TEN.pow(result).compareTo(x) >= 0);
assertTrue(result == 0 || TEN.pow(result - 1).compareTo(x) < 0);
}
}
}
Aggregations