public class MoreMath extends Object
| Modifier and Type | Method and Description |
|---|---|
static BigDecimal |
absDifference(BigDecimal x,
BigDecimal y)
Returns the absolute difference of the given numbers.
|
static BigInteger |
absDifference(BigInteger x,
BigInteger y)
Returns the absolute difference of the given numbers.
|
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 BigDecimal |
absExact(BigDecimal x)
Returns the absolute value of the given number.
|
static BigInteger |
absExact(BigInteger x)
Returns the absolute value of the given number.
|
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 BigDecimal |
addExact(BigDecimal x,
BigDecimal y)
Returns the sum of the given numbers.
|
static BigInteger |
addExact(BigInteger x,
BigInteger y)
Returns the sum of the given numbers.
|
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 BigInteger |
decrementExact(BigInteger x)
Returns the given number decremented by one.
|
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 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 BigDecimal |
fractionalPart(BigDecimal x)
Returns the fractional part of 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 BigInteger |
gcd(BigInteger x,
BigInteger y)
Returns the greatest common divisor of the given numbers.
|
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 BigInteger |
incrementExact(BigInteger x)
Returns the given number incremented by one.
|
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 boolean |
isEven(BigInteger x)
Checks whether the given number is even.
|
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 |
isOdd(BigInteger x)
Checks whether the given number is odd.
|
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 BigInteger |
lcm(BigInteger x,
BigInteger y)
Returns the least common multiple of the given numbers.
|
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 double |
ld(double x)
Returns the dual (base
2) logarithm of the given number. |
static double |
ln(double x)
Returns the natural (base
e) logarithm of the given number. |
static BigDecimal |
multiplyExact(BigDecimal x,
BigDecimal y)
Returns the product of the given numbers.
|
static BigInteger |
multiplyExact(BigInteger x,
BigInteger y)
Returns the product of the given numbers.
|
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 BigDecimal |
negateExact(BigDecimal x)
Returns the negation of the given number.
|
static BigInteger |
negateExact(BigInteger x)
Returns the negation of the given number.
|
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 int |
signum(BigDecimal x)
Returns the signum of the given value.
|
static int |
signum(BigInteger x)
Returns the signum of the given value.
|
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 BigDecimal |
subtractExact(BigDecimal x,
BigDecimal y)
Returns the difference of the given arguments.
|
static BigInteger |
subtractExact(BigInteger x,
BigInteger y)
Returns the difference of the given arguments.
|
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 BigInteger |
toBigIntegerExact(BigDecimal x)
Returns the
BigInteger value of the given number. |
static int |
toIntExact(BigDecimal x)
Returns the
int value of the given number. |
static int |
toIntExact(BigInteger x)
Returns the
int 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 long |
toLongExact(BigDecimal x)
Returns the
long value of the given number. |
static long |
toLongExact(BigInteger x)
Returns the
long 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 short |
toShortExact(BigDecimal x)
Returns the
short value of the given number. |
static short |
toShortExact(BigInteger x)
Returns the
short 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. |
public static BigDecimal absDifference(BigDecimal x, BigDecimal y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static BigInteger absDifference(BigInteger x, BigInteger y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static double absDifference(double x,
double y)
IllegalArgumentException - if x is not finiteIllegalArgumentException - if y is not finitepublic static float absDifference(float x,
float y)
IllegalArgumentException - if x is not finiteIllegalArgumentException - if y is not finitepublic static int absDifference(int x,
int y)
ArithmeticException - if the result overflows an int.public static long absDifference(long x,
long y)
ArithmeticException - if the result overflows an int.public static BigDecimal absExact(BigDecimal x)
IllegalArgumentException - if x is nullpublic static BigInteger absExact(BigInteger x)
IllegalArgumentException - if x is nullpublic static double absExact(double x)
IllegalArgumentException - if x is NaNpublic static float absExact(float x)
IllegalArgumentException - if x is NaNpublic static int absExact(int x)
ArithmeticException - if x is equal to Integer.MIN_VALUE.public static long absExact(long x)
ArithmeticException - if x is equal to Long.MIN_VALUE.public static BigDecimal addExact(BigDecimal x, BigDecimal y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static BigInteger addExact(BigInteger x, BigInteger y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static int addExact(int x,
int y)
ArithmeticException - if the result overflows an int.public static long addExact(long x,
long y)
ArithmeticException - if the result overflows a long.public static BigInteger decrementExact(BigInteger x)
IllegalArgumentException - if x is nullpublic static int decrementExact(int x)
ArithmeticException - if the result overflows an int.public static long decrementExact(long x)
ArithmeticException - if the result overflows a long.public static boolean equals(double x,
double y,
double tolerance)
IllegalArgumentException - if x is not finiteIllegalArgumentException - if y is not finiteIllegalArgumentException - if tolerance is not finiteIllegalArgumentException - if tolerance is negativepublic static boolean equals(float x,
float y,
float tolerance)
IllegalArgumentException - if x is not finiteIllegalArgumentException - if y is not finiteIllegalArgumentException - if tolerance is not finiteIllegalArgumentException - if tolerance is negativepublic static BigDecimal fractionalPart(BigDecimal x)
IllegalArgumentException - if x is nullpublic static double fractionalPart(double x)
IllegalArgumentException - if x is not finitepublic static float fractionalPart(float x)
IllegalArgumentException - if x is not finitepublic static BigInteger gcd(BigInteger x, BigInteger y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static int gcd(int x,
int y)
ArithmeticException - if x is equal to Integer.MIN_VALUE.ArithmeticException - if y is equal to Integer.MIN_VALUE.public static long gcd(long x,
long y)
ArithmeticException - if x is equal to Long.MIN_VALUE.ArithmeticException - if y is equal to Long.MIN_VALUE.public static BigInteger incrementExact(BigInteger x)
IllegalArgumentException - if x is nullpublic static int incrementExact(int x)
ArithmeticException - if the result overflows an int.public static long incrementExact(long x)
ArithmeticException - if the result overflows a long.public static boolean isEven(BigInteger x)
IllegalArgumentException - if x is nullpublic static boolean isEven(int x)
public static boolean isEven(long x)
public static boolean isOdd(BigInteger x)
IllegalArgumentException - if x is nullpublic static boolean isOdd(int x)
public static boolean isOdd(long x)
public static BigInteger lcm(BigInteger x, BigInteger y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static int lcm(int x,
int y)
ArithmeticException - if x is equal to Integer.MIN_VALUE.ArithmeticException - if y is equal to Integer.MIN_VALUE.public static long lcm(long x,
long y)
ArithmeticException - if x is equal to Long.MIN_VALUE.ArithmeticException - if y is equal to Long.MIN_VALUE.public static double ld(double x)
2) logarithm of the given number.IllegalArgumentException - if x is not finitepublic static double ln(double x)
e) logarithm of the given number.IllegalArgumentException - if x is not finitepublic static BigDecimal multiplyExact(BigDecimal x, BigDecimal y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static BigInteger multiplyExact(BigInteger x, BigInteger y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static int multiplyExact(int x,
int y)
ArithmeticException - if the result overflows an int.public static long multiplyExact(long x,
long y)
ArithmeticException - if the result overflows a long.public static BigDecimal negateExact(BigDecimal x)
IllegalArgumentException - if x is nullpublic static BigInteger negateExact(BigInteger x)
IllegalArgumentException - if x is nullpublic static double negateExact(double x)
IllegalArgumentException - if x is NaNpublic static float negateExact(float x)
IllegalArgumentException - if x is NaNpublic static int negateExact(int x)
ArithmeticException - if x is equal to Integer.MIN_VALUE.public static long negateExact(long x)
ArithmeticException - if x is equal to Long.MIN_VALUE.public static int signum(BigDecimal x)
IllegalArgumentException - if x is nullpublic static int signum(BigInteger x)
IllegalArgumentException - if x is nullpublic static int signum(double x)
IllegalArgumentException - if x is NaNpublic static int signum(float x)
IllegalArgumentException - if x is NaNpublic static int signum(int x)
public static int signum(long x)
public static BigDecimal subtractExact(BigDecimal x, BigDecimal y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static BigInteger subtractExact(BigInteger x, BigInteger y)
IllegalArgumentException - if x is nullIllegalArgumentException - if y is nullpublic static int subtractExact(int x,
int y)
ArithmeticException - if the result overflows an int.public static long subtractExact(long x,
long y)
ArithmeticException - if the result overflows a long.public static BigInteger toBigIntegerExact(BigDecimal x)
BigInteger value of the given number.ArithmeticException - if x has a non-zero fractional part.IllegalArgumentException - if x is nullpublic static int toIntExact(BigDecimal x)
int value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows an int.IllegalArgumentException - if x is nullpublic static int toIntExact(BigInteger x)
int value of the given number.ArithmeticException - if x overflows an int.IllegalArgumentException - if x is nullpublic static int toIntExact(double x)
int value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows an int.IllegalArgumentException - if x is not finitepublic static int toIntExact(float x)
int value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows an int.IllegalArgumentException - if x is not finitepublic static int toIntExact(long x)
int value of the given number.ArithmeticException - if x overflows an int.public static long toLongExact(BigDecimal x)
long value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows a long.IllegalArgumentException - if x is nullpublic static long toLongExact(BigInteger x)
long value of the given number.ArithmeticException - if x overflows a long.IllegalArgumentException - if x is nullpublic static long toLongExact(double x)
long value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows a long.IllegalArgumentException - if x is not finitepublic static long toLongExact(float x)
long value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows a long.IllegalArgumentException - if x is not finitepublic static short toShortExact(BigDecimal x)
short value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows a short.IllegalArgumentException - if x is nullpublic static short toShortExact(BigInteger x)
short value of the given number.ArithmeticException - if x overflows a short.IllegalArgumentException - if x is nullpublic static short toShortExact(double x)
short value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows a short.IllegalArgumentException - if x is not finitepublic static short toShortExact(float x)
short value of the given number.ArithmeticException - if x has a non-zero fractional part.ArithmeticException - if x overflows a short.IllegalArgumentException - if x is not finitepublic static short toShortExact(int x)
short value of the given number.ArithmeticException - if x overflows a short.public static short toShortExact(long x)
short value of the given number.ArithmeticException - if x overflows a short.