public class MoreMath
extends java.lang.Object
| Modifier and Type | Method | Description |
|---|---|---|
static double |
absDifference(double x,
double y) |
Returns the absolute difference of the given numbers.
|
static float |
absDifference(float x,
float y) |
Returns the absolute difference of the given numbers.
|
static int |
absDifference(int x,
int y) |
Returns the absolute difference of the given numbers.
|
static long |
absDifference(long x,
long y) |
Returns the absolute difference of the given numbers.
|
static java.math.BigDecimal |
absDifference(java.math.BigDecimal x,
java.math.BigDecimal y) |
Returns the absolute difference of the given numbers.
|
static java.math.BigInteger |
absDifference(java.math.BigInteger x,
java.math.BigInteger y) |
Returns the absolute difference of the given numbers.
|
static double |
absExact(double x) |
Returns the absolute value of the given number.
|
static float |
absExact(float x) |
Returns the absolute value of the given number.
|
static int |
absExact(int x) |
Returns the absolute value of the given number.
|
static long |
absExact(long x) |
Returns the absolute value of the given number.
|
static java.math.BigDecimal |
absExact(java.math.BigDecimal x) |
Returns the absolute value of the given number.
|
static java.math.BigInteger |
absExact(java.math.BigInteger x) |
Returns the absolute value of the given number.
|
static int |
addExact(int x,
int y) |
Returns the sum of the given numbers.
|
static long |
addExact(long x,
long y) |
Returns the sum of the given numbers.
|
static java.math.BigDecimal |
addExact(java.math.BigDecimal x,
java.math.BigDecimal y) |
Returns the sum of the given numbers.
|
static java.math.BigInteger |
addExact(java.math.BigInteger x,
java.math.BigInteger y) |
Returns the sum of the given numbers.
|
static int |
ceilToMultiple(int number,
int base) |
Returns the smallest (closest to negative infinity) multiple of the given base that is greater or equal to the given number.
|
static long |
ceilToMultiple(long number,
long base) |
Returns the smallest (closest to negative infinity) multiple of the given base that is greater or equal to the given number.
|
static java.math.BigDecimal |
ceilToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base) |
Returns the smallest (closest to negative infinity) multiple of the given base that is greater or equal to the given number.
|
static java.math.BigInteger |
ceilToMultiple(java.math.BigInteger number,
java.math.BigInteger base) |
Returns the smallest (closest to negative infinity) multiple of the given base that is greater or equal to the given number.
|
static int |
decrementExact(int x) |
Returns the given number decremented by one.
|
static long |
decrementExact(long x) |
Returns the given number decremented by one.
|
static java.math.BigInteger |
decrementExact(java.math.BigInteger x) |
Returns the given number decremented by one.
|
static boolean |
equals(double x,
double y,
double tolerance) |
Checks whether the given numbers are considered equal in the context of the given tolerance.
|
static boolean |
equals(float x,
float y,
float tolerance) |
Checks whether the given numbers are considered equal in the context of the given tolerance.
|
static int |
floorToMultiple(int number,
int base) |
Returns the largest (closest to positive negative) multiple of the given base that is smaller or equal to the given number.
|
static long |
floorToMultiple(long number,
long base) |
Returns the largest (closest to positive negative) multiple of the given base that is smaller or equal to the given number.
|
static java.math.BigDecimal |
floorToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base) |
Returns the largest (closest to positive infinity) multiple of the given base that is smaller or equal to the given number.
|
static java.math.BigInteger |
floorToMultiple(java.math.BigInteger number,
java.math.BigInteger base) |
Returns the largest (closest to positive negative) multiple of the given base that is smaller or equal to the given number.
|
static double |
fractionalPart(double x) |
Returns the fractional part of the given number.
|
static float |
fractionalPart(float x) |
Returns the fractional part of the given number.
|
static java.math.BigDecimal |
fractionalPart(java.math.BigDecimal x) |
Returns the fractional part of the given number.
|
static int |
gcd(int x,
int y) |
Returns the greatest common divisor of the given numbers.
|
static long |
gcd(long x,
long y) |
Returns the greatest common divisor of the given numbers.
|
static java.math.BigInteger |
gcd(java.math.BigInteger x,
java.math.BigInteger y) |
Returns the greatest common divisor of the given numbers.
|
static int |
incrementExact(int x) |
Returns the given number incremented by one.
|
static long |
incrementExact(long x) |
Returns the given number incremented by one.
|
static java.math.BigInteger |
incrementExact(java.math.BigInteger x) |
Returns the given number incremented by one.
|
static long |
integralPart(double x) |
Returns the integral part of the given number.
|
static int |
integralPart(float x) |
Returns the integral part of the given number.
|
static java.math.BigDecimal |
integralPart(java.math.BigDecimal x) |
Returns the integral part of the given number.
|
static boolean |
isEven(int x) |
Checks whether the given number is even.
|
static boolean |
isEven(long x) |
Checks whether the given number is even.
|
static boolean |
isEven(java.math.BigInteger x) |
Checks whether the given number is even.
|
static boolean |
isOdd(int x) |
Checks whether the given number is odd.
|
static boolean |
isOdd(long x) |
Checks whether the given number is odd.
|
static boolean |
isOdd(java.math.BigInteger x) |
Checks whether the given number is odd.
|
static int |
lcm(int x,
int y) |
Returns the least common multiple of the given numbers.
|
static long |
lcm(long x,
long y) |
Returns the least common multiple of the given numbers.
|
static java.math.BigInteger |
lcm(java.math.BigInteger x,
java.math.BigInteger y) |
Returns the least common multiple of the given numbers.
|
static int |
magnitude(java.math.BigDecimal x) |
Returns the magnitude (the number of digits left to the decimal point) of the given number.
|
static int |
multiplyExact(int x,
int y) |
Returns the product of the given numbers.
|
static long |
multiplyExact(long x,
long y) |
Returns the product of the given numbers.
|
static java.math.BigDecimal |
multiplyExact(java.math.BigDecimal x,
java.math.BigDecimal y) |
Returns the product of the given numbers.
|
static java.math.BigInteger |
multiplyExact(java.math.BigInteger x,
java.math.BigInteger y) |
Returns the product of the given numbers.
|
static double |
negateExact(double x) |
Returns the negation of the given number.
|
static float |
negateExact(float x) |
Returns the negation of the given number.
|
static int |
negateExact(int x) |
Returns the negation of the given number.
|
static long |
negateExact(long x) |
Returns the negation of the given number.
|
static java.math.BigDecimal |
negateExact(java.math.BigDecimal x) |
Returns the negation of the given number.
|
static java.math.BigInteger |
negateExact(java.math.BigInteger x) |
Returns the negation of the given number.
|
static java.math.BigDecimal |
pow(java.math.BigDecimal x,
long n,
int scale) |
Returns the n-th power of the given number.
|
static int |
powExact(int base,
int exponent) |
Returns the given base raised to the power of the given exponent.
|
static long |
powExact(long base,
int exponent) |
Returns the given base raised to the power of the given exponent.
|
static java.math.BigDecimal |
root(java.math.BigDecimal x,
int n,
int scale) |
Returns the n-th root of the given number.
|
static int |
roundToMultiple(int number,
int base) |
Returns a multiple of the given base that is closest to the given number.
|
static long |
roundToMultiple(long number,
long base) |
Returns a multiple of the given base that is closest to the given number.
|
static java.math.BigDecimal |
roundToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base) |
Returns a multiple of the given base that is closest to the given number.
|
static java.math.BigDecimal |
roundToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base,
java.math.RoundingMode roundingMode) |
Returns a multiple of the given base that is closest to the given number.
|
static java.math.BigInteger |
roundToMultiple(java.math.BigInteger number,
java.math.BigInteger base) |
Returns a multiple of the given base that is closest to the given number.
|
static java.math.BigInteger |
roundToMultiple(java.math.BigInteger number,
java.math.BigInteger base,
java.math.RoundingMode roundingMode) |
Returns a multiple of the given base that is closest to the given number.
|
static int |
signum(double x) |
Returns the signum of the given value.
|
static int |
signum(float x) |
Returns the signum of the given value.
|
static int |
signum(int x) |
Returns the signum of the given value.
|
static int |
signum(long x) |
Returns the signum of the given value.
|
static int |
signum(java.math.BigDecimal x) |
Returns the signum of the given value.
|
static int |
signum(java.math.BigInteger x) |
Returns the signum of the given value.
|
static int |
subtractExact(int x,
int y) |
Returns the difference of the given arguments.
|
static long |
subtractExact(long x,
long y) |
Returns the difference of the given arguments.
|
static java.math.BigDecimal |
subtractExact(java.math.BigDecimal x,
java.math.BigDecimal y) |
Returns the difference of the given arguments.
|
static java.math.BigInteger |
subtractExact(java.math.BigInteger x,
java.math.BigInteger y) |
Returns the difference of the given arguments.
|
static java.math.BigInteger |
toBigIntegerExact(java.math.BigDecimal x) |
Returns the
BigInteger value of the given number. |
static int |
toIntExact(double x) |
Returns the
int value of the given number. |
static int |
toIntExact(float x) |
Returns the
int value of the given number. |
static int |
toIntExact(long x) |
Returns the
int value of the given number. |
static int |
toIntExact(java.math.BigDecimal x) |
Returns the
int value of the given number. |
static int |
toIntExact(java.math.BigInteger x) |
Returns the
int value of the given number. |
static long |
toLongExact(double x) |
Returns the
long value of the given number. |
static long |
toLongExact(float x) |
Returns the
long value of the given number. |
static long |
toLongExact(java.math.BigDecimal x) |
Returns the
long value of the given number. |
static long |
toLongExact(java.math.BigInteger x) |
Returns the
long value of the given number. |
static short |
toShortExact(double x) |
Returns the
short value of the given number. |
static short |
toShortExact(float x) |
Returns the
short value of the given number. |
static short |
toShortExact(int x) |
Returns the
short value of the given number. |
static short |
toShortExact(long x) |
Returns the
short value of the given number. |
static short |
toShortExact(java.math.BigDecimal x) |
Returns the
short value of the given number. |
static short |
toShortExact(java.math.BigInteger x) |
Returns the
short value of the given number. |
public static java.math.BigDecimal absDifference(java.math.BigDecimal x,
java.math.BigDecimal y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static java.math.BigInteger absDifference(java.math.BigInteger x,
java.math.BigInteger y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static double absDifference(double x,
double y)
java.lang.IllegalArgumentException - if x is not finitejava.lang.IllegalArgumentException - if y is not finitepublic static float absDifference(float x,
float y)
java.lang.IllegalArgumentException - if x is not finitejava.lang.IllegalArgumentException - if y is not finitepublic static int absDifference(int x,
int y)
java.lang.ArithmeticException - if the result does not exactly fit an intpublic static long absDifference(long x,
long y)
java.lang.ArithmeticException - if the result does not exactly fit an intpublic static java.math.BigDecimal absExact(java.math.BigDecimal x)
java.lang.IllegalArgumentException - if x is nullpublic static java.math.BigInteger absExact(java.math.BigInteger x)
java.lang.IllegalArgumentException - if x is nullpublic static double absExact(double x)
java.lang.IllegalArgumentException - if x is NaNpublic static float absExact(float x)
java.lang.IllegalArgumentException - if x is NaNpublic static int absExact(int x)
java.lang.ArithmeticException - if x is equal to Integer.MIN_VALUEpublic static long absExact(long x)
java.lang.ArithmeticException - if x is equal to Long.MIN_VALUEpublic static java.math.BigDecimal addExact(java.math.BigDecimal x,
java.math.BigDecimal y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static java.math.BigInteger addExact(java.math.BigInteger x,
java.math.BigInteger y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static int addExact(int x,
int y)
java.lang.ArithmeticException - if the result does not exactly fit an intpublic static long addExact(long x,
long y)
java.lang.ArithmeticException - if the result does not exactly fit a longpublic static java.math.BigDecimal ceilToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivepublic static java.math.BigInteger ceilToMultiple(java.math.BigInteger number,
java.math.BigInteger base)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivepublic static int ceilToMultiple(int number,
int base)
java.lang.IllegalArgumentException - if base is not positivepublic static long ceilToMultiple(long number,
long base)
java.lang.IllegalArgumentException - if base is not positivepublic static java.math.BigInteger decrementExact(java.math.BigInteger x)
java.lang.IllegalArgumentException - if x is nullpublic static int decrementExact(int x)
java.lang.ArithmeticException - if the result does not exactly fit an intpublic static long decrementExact(long x)
java.lang.ArithmeticException - if the result does not exactly fit a longpublic static boolean equals(double x,
double y,
double tolerance)
java.lang.IllegalArgumentException - if x is not finitejava.lang.IllegalArgumentException - if y is not finitejava.lang.IllegalArgumentException - if tolerance is not finitejava.lang.IllegalArgumentException - if tolerance is negativepublic static boolean equals(float x,
float y,
float tolerance)
java.lang.IllegalArgumentException - if x is not finitejava.lang.IllegalArgumentException - if y is not finitejava.lang.IllegalArgumentException - if tolerance is not finitejava.lang.IllegalArgumentException - if tolerance is negativepublic static java.math.BigDecimal floorToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivepublic static java.math.BigInteger floorToMultiple(java.math.BigInteger number,
java.math.BigInteger base)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivepublic static int floorToMultiple(int number,
int base)
java.lang.IllegalArgumentException - if base is not positivepublic static long floorToMultiple(long number,
long base)
java.lang.IllegalArgumentException - if base is not positivepublic static java.math.BigDecimal fractionalPart(java.math.BigDecimal x)
java.lang.IllegalArgumentException - if x is nullpublic static double fractionalPart(double x)
java.lang.IllegalArgumentException - if x is not finitepublic static float fractionalPart(float x)
java.lang.IllegalArgumentException - if x is not finitepublic static java.math.BigInteger gcd(java.math.BigInteger x,
java.math.BigInteger y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static int gcd(int x,
int y)
java.lang.ArithmeticException - if x is equal to Integer.MIN_VALUEjava.lang.ArithmeticException - if y is equal to Integer.MIN_VALUEpublic static long gcd(long x,
long y)
java.lang.ArithmeticException - if x is equal to Long.MIN_VALUEjava.lang.ArithmeticException - if y is equal to Long.MIN_VALUEpublic static java.math.BigInteger incrementExact(java.math.BigInteger x)
java.lang.IllegalArgumentException - if x is nullpublic static int incrementExact(int x)
java.lang.ArithmeticException - if the result does not exactly fit an intpublic static long incrementExact(long x)
java.lang.ArithmeticException - if the result does not exactly fit a longpublic static java.math.BigDecimal integralPart(java.math.BigDecimal x)
java.lang.IllegalArgumentException - if x is nullpublic static long integralPart(double x)
java.lang.IllegalArgumentException - if x is not finitepublic static int integralPart(float x)
java.lang.IllegalArgumentException - if x is not finitepublic static boolean isEven(java.math.BigInteger x)
java.lang.IllegalArgumentException - if x is nullpublic static boolean isEven(int x)
public static boolean isEven(long x)
public static boolean isOdd(java.math.BigInteger x)
java.lang.IllegalArgumentException - if x is nullpublic static boolean isOdd(int x)
public static boolean isOdd(long x)
public static java.math.BigInteger lcm(java.math.BigInteger x,
java.math.BigInteger y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static int lcm(int x,
int y)
java.lang.ArithmeticException - if x is equal to Integer.MIN_VALUEjava.lang.ArithmeticException - if y is equal to Integer.MIN_VALUEpublic static long lcm(long x,
long y)
java.lang.ArithmeticException - if x is equal to Long.MIN_VALUEjava.lang.ArithmeticException - if y is equal to Long.MIN_VALUEpublic static int magnitude(java.math.BigDecimal x)
java.lang.IllegalArgumentException - if x is nullpublic static java.math.BigDecimal multiplyExact(java.math.BigDecimal x,
java.math.BigDecimal y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static java.math.BigInteger multiplyExact(java.math.BigInteger x,
java.math.BigInteger y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static int multiplyExact(int x,
int y)
java.lang.ArithmeticException - if the result does not exactly fit an intpublic static long multiplyExact(long x,
long y)
java.lang.ArithmeticException - if the result does not exactly fit a longpublic static java.math.BigDecimal negateExact(java.math.BigDecimal x)
java.lang.IllegalArgumentException - if x is nullpublic static java.math.BigInteger negateExact(java.math.BigInteger x)
java.lang.IllegalArgumentException - if x is nullpublic static double negateExact(double x)
java.lang.IllegalArgumentException - if x is NaNpublic static float negateExact(float x)
java.lang.IllegalArgumentException - if x is NaNpublic static int negateExact(int x)
java.lang.ArithmeticException - if x is equal to Integer.MIN_VALUEpublic static long negateExact(long x)
java.lang.ArithmeticException - if x is equal to Long.MIN_VALUEpublic static java.math.BigDecimal pow(java.math.BigDecimal x,
long n,
int scale)
Powering BigDecimal.ZERO to the value of 0 returns BigDecimal.ONE.
java.lang.ArithmeticException - if n is out of rangejava.lang.IllegalArgumentException - if x is nullpublic static int powExact(int base,
int exponent)
java.lang.ArithmeticException - if the result does not exactly fit an intjava.lang.IllegalArgumentException - if exponent is negativepublic static long powExact(long base,
int exponent)
java.lang.ArithmeticException - if the result does not exactly fit an intjava.lang.IllegalArgumentException - if exponent is negativepublic static java.math.BigDecimal root(java.math.BigDecimal x,
int n,
int scale)
java.lang.ArithmeticException - if x is negative and n is evenjava.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if n is not positivepublic static java.math.BigDecimal roundToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivepublic static java.math.BigDecimal roundToMultiple(java.math.BigDecimal number,
java.math.BigDecimal base,
java.math.RoundingMode roundingMode)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivejava.lang.IllegalArgumentException - if roundingMode is nullpublic static java.math.BigInteger roundToMultiple(java.math.BigInteger number,
java.math.BigInteger base)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivepublic static java.math.BigInteger roundToMultiple(java.math.BigInteger number,
java.math.BigInteger base,
java.math.RoundingMode roundingMode)
java.lang.IllegalArgumentException - if number is nulljava.lang.IllegalArgumentException - if base is null or is not positivejava.lang.IllegalArgumentException - if roundingMode is nullpublic static int roundToMultiple(int number,
int base)
java.lang.IllegalArgumentException - if base is not positivepublic static long roundToMultiple(long number,
long base)
java.lang.IllegalArgumentException - if base is not positivepublic static int signum(java.math.BigDecimal x)
java.lang.IllegalArgumentException - if x is nullpublic static int signum(java.math.BigInteger x)
java.lang.IllegalArgumentException - if x is nullpublic static int signum(double x)
java.lang.IllegalArgumentException - if x is NaNpublic static int signum(float x)
java.lang.IllegalArgumentException - if x is NaNpublic static int signum(int x)
public static int signum(long x)
public static java.math.BigDecimal subtractExact(java.math.BigDecimal x,
java.math.BigDecimal y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static java.math.BigInteger subtractExact(java.math.BigInteger x,
java.math.BigInteger y)
java.lang.IllegalArgumentException - if x is nulljava.lang.IllegalArgumentException - if y is nullpublic static int subtractExact(int x,
int y)
java.lang.ArithmeticException - if the result does not exactly fit an intpublic static long subtractExact(long x,
long y)
java.lang.ArithmeticException - if the result does not exactly fit a longpublic static java.math.BigInteger toBigIntegerExact(java.math.BigDecimal x)
BigInteger value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.IllegalArgumentException - if x is nullpublic static int toIntExact(java.math.BigDecimal x)
int value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit an intjava.lang.IllegalArgumentException - if x is nullpublic static int toIntExact(java.math.BigInteger x)
int value of the given number.java.lang.ArithmeticException - if x does not exactly fit an intjava.lang.IllegalArgumentException - if x is nullpublic static int toIntExact(double x)
int value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit an intjava.lang.IllegalArgumentException - if x is not finitepublic static int toIntExact(float x)
int value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit an intjava.lang.IllegalArgumentException - if x is not finitepublic static int toIntExact(long x)
int value of the given number.java.lang.ArithmeticException - if x does not exactly fit an intpublic static long toLongExact(java.math.BigDecimal x)
long value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit a longjava.lang.IllegalArgumentException - if x is nullpublic static long toLongExact(java.math.BigInteger x)
long value of the given number.java.lang.ArithmeticException - if x does not exactly fit a longjava.lang.IllegalArgumentException - if x is nullpublic static long toLongExact(double x)
long value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit a longjava.lang.IllegalArgumentException - if x is not finitepublic static long toLongExact(float x)
long value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit a longjava.lang.IllegalArgumentException - if x is not finitepublic static short toShortExact(java.math.BigDecimal x)
short value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit a shortjava.lang.IllegalArgumentException - if x is nullpublic static short toShortExact(java.math.BigInteger x)
short value of the given number.java.lang.ArithmeticException - if x does not exactly fit a shortjava.lang.IllegalArgumentException - if x is nullpublic static short toShortExact(double x)
short value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit a shortjava.lang.IllegalArgumentException - if x is not finitepublic static short toShortExact(float x)
short value of the given number.java.lang.ArithmeticException - if x has a non-zero fractional partjava.lang.ArithmeticException - if x does not exactly fit a shortjava.lang.IllegalArgumentException - if x is not finitepublic static short toShortExact(int x)
short value of the given number.java.lang.ArithmeticException - if x does not exactly fit a shortpublic static short toShortExact(long x)
short value of the given number.java.lang.ArithmeticException - if x does not exactly fit a short