MathGuava.java 916 B

12345678910111213141516171819202122232425
  1. package org.example.math;
  2. import com.google.common.math.*;
  3. import java.math.BigInteger;
  4. import java.math.RoundingMode;
  5. import static java.math.RoundingMode.CEILING;
  6. import static java.math.RoundingMode.FLOOR;
  7. public class MathGuava {
  8. public static void main(String[] args) {
  9. int logFloor = LongMath.log2(3, FLOOR);
  10. int mustNotOverflow = IntMath.checkedMultiply(121, 8746);
  11. long quotient = LongMath.divide(18, 3, RoundingMode.UNNECESSARY); // fail fast on non-multiple of 3
  12. BigInteger nearestInteger = DoubleMath.roundToBigInteger(348.33, RoundingMode.HALF_EVEN);
  13. BigInteger sideLength = BigIntegerMath.sqrt(new BigInteger(String.valueOf(144)), CEILING);
  14. System.out.println(logFloor);
  15. System.out.println(mustNotOverflow);
  16. System.out.println(quotient);
  17. System.out.println(nearestInteger);
  18. System.out.println(sideLength);
  19. }
  20. }