public final class Maths extends Object
| Modifier and Type | Method and Description |
|---|---|
static double |
add(long a,
long b,
long c)
return a + b / c as a double
|
static long |
agitate(long l)
Performs a series of bit operations on a long value to "agitate" the bits.
|
static double |
asDouble(long value,
int exponent,
boolean negative,
int decimalPlaces)
Convert components to a double value
|
static double |
ceilN(double d,
double digits) |
static double |
ceilN(double d,
int digits)
Rounds up the given double value to the nearest higher number,
accurate to the specified number of decimal places.
|
static int |
digits(long num)
Returns the number of digits in the given number.
|
static long |
divideRoundUp(long dividend,
long divisor)
Divide
dividend by divisor, if division is not integral the result is rounded up. |
static long |
fives(int decimalPlaces)
Returns the power of five for the given decimal places.
|
static double |
floorN(double d,
double digits) |
static double |
floorN(double d,
int digits)
Rounds down the given double value to the nearest lower number,
accurate to the specified number of decimal places.
|
static int |
hash(Object o) |
static int |
hash(Object o1,
Object o2) |
static int |
hash(Object o1,
Object o2,
Object o3) |
static int |
hash(Object o1,
Object o2,
Object o3,
Object o4) |
static int |
hash(Object o1,
Object o2,
Object o3,
Object o4,
Object o5) |
static int |
hash32(@NotNull CharSequence cs)
Deprecated.
|
static int |
hash32(long l0)
Deprecated.
|
static int |
hash32(@NotNull String s)
Deprecated.
|
static int |
hash32(@NotNull StringBuilder s)
Deprecated.
|
static long |
hash64(@Nullable CharSequence cs) |
static long |
hash64(long l0)
A simple hashing algorithm for a 64-bit value
|
static long |
hash64(long l0,
long l1)
Deprecated.
|
static long |
hash64(@NotNull String s)
Computes a 64-bit hash value for the given string.
|
static long |
hash64(@NotNull StringBuilder s)
Computes a 64-bit hash value for the given StringBuilder.
|
static int |
intLog2(long num)
Returns rounded down log2
num, e. |
static boolean |
isPowerOf2(long n) |
static int |
nextPower2(int n,
int min)
Returns the next power of two.
|
static long |
nextPower2(long n,
long min)
Returns the next power of two.
|
static double |
round1(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round1up(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round2(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round2up(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round3(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round3up(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round4(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round4up(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round5(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round5up(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round6(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round6up(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round7(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round7up(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round8(double d)
Performs a round which is accurate to within 1 ulp.
|
static double |
round8up(double d)
Performs a round which is accurate to within 1 ulp.
|
static long |
roundingFactor(double digits) |
static long |
roundingFactor(int digits) |
static double |
roundN(double d,
double digits) |
static double |
roundN(double d,
int digits)
Performs a round which is accurate to within 1 ulp.
|
static double |
roundNup(double d,
int digits)
Performs a round which is accurate to within 1 ulp.
|
static boolean |
same(double a,
double b)
Checks if two double values are the same.
|
static boolean |
same(float a,
float b)
Checks if two float values are the same.
|
static long |
tens(int decimalPlaces)
Returns the power of ten for the given decimal places.
|
static short |
toInt16(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows a short. |
static int |
toInt32(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows an int. |
static int |
toInt32(long value,
@NotNull String msg)
Returns the value of the
long argument;
throwing an exception if the value overflows an int. |
static byte |
toInt8(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows a byte. |
static int |
toUInt16(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows an unsigned short (0xFFFF). |
static int |
toUInt31(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows an unsigned 31 bit value (0x7FFFFFFFL). |
static long |
toUInt32(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows an unsigned int (0xFFFFFFFFL). |
static short |
toUInt8(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows an unsigned byte (0xFF). |
public static double roundN(double d,
int digits)
d - value to rounddigits - 0 to 18 digits of precisionpublic static double roundNup(double d,
int digits)
d - value to roundpublic static long roundingFactor(int digits)
public static long roundingFactor(double digits)
public static double ceilN(double d,
int digits)
d - The double value to be rounded up.digits - The number of decimal places to which the value is to be rounded.public static double floorN(double d,
int digits)
d - The double value to be rounded down.digits - The number of decimal places to which the value is to be rounded.public static double roundN(double d,
double digits)
public static double ceilN(double d,
double digits)
public static double floorN(double d,
double digits)
public static double round1(double d)
d - value to roundpublic static double round1up(double d)
d - value to roundpublic static double round2(double d)
d - value to roundpublic static double round2up(double d)
d - value to roundpublic static double round3(double d)
d - value to roundpublic static double round3up(double d)
d - value to roundpublic static double round4(double d)
d - value to roundpublic static double round4up(double d)
d - value to roundpublic static double round5(double d)
d - value to roundpublic static double round5up(double d)
d - value to roundpublic static double round6(double d)
d - value to roundpublic static double round6up(double d)
d - value to roundpublic static double round7(double d)
d - value to roundpublic static double round7up(double d)
d - value to roundpublic static double round8(double d)
d - value to roundpublic static double round8up(double d)
d - value to roundpublic static int nextPower2(int n,
int min)
throws IllegalArgumentException
n - to find the next power of two frommin - if n < min then use minIllegalArgumentException - if the provided min value is not a power of two.public static long nextPower2(long n,
long min)
throws IllegalArgumentException
n - to find the next power of two frommin - if n < min then use minIllegalArgumentException - if the provided min value is not a power of two.public static boolean isPowerOf2(long n)
@Deprecated public static int hash32(@NotNull @NotNull CharSequence cs)
@Deprecated public static int hash32(@NotNull @NotNull String s)
hash64(String) method,
and then combining the upper and lower 32 bits of the hash using XOR.s - the string to compute the hash forIllegalArgumentException - if s is null@Deprecated public static int hash32(@NotNull @NotNull StringBuilder s)
hash64(StringBuilder) method,
and then combining the upper and lower 32 bits of the hash using XOR.s - the StringBuilder to compute the hash forIllegalArgumentException - if s is null@Deprecated public static int hash32(long l0)
public static long hash64(@Nullable
@Nullable CharSequence cs)
public static long hash64(@NotNull
@NotNull String s)
s - the string to compute the hash forIllegalArgumentException - if s is nullpublic static long hash64(@NotNull
@NotNull StringBuilder s)
s - the string to compute the hash forIllegalArgumentException - if s is nullpublic static int intLog2(long num)
throws IllegalArgumentException
num, e. g.: intLog2(1) == 0,
intLog2(2) == 1, intLog2(7) == 2, intLog2(8) == 3, etc.IllegalArgumentException - if the given number <= 0public static byte toInt8(long value)
throws ArithmeticException
long argument;
throwing an exception if the value overflows a byte.value - the long valueArithmeticException - if the argument overflows a bytepublic static short toInt16(long value)
throws ArithmeticException
long argument;
throwing an exception if the value overflows a short.value - the long valueArithmeticException - if the argument overflows a shortpublic static int toInt32(long value,
@NotNull
@NotNull String msg)
throws ArithmeticException
long argument;
throwing an exception if the value overflows an int.value - the long valuemsg - to use in a potential exception messageArithmeticException - if the argument overflows an intpublic static int toInt32(long value)
throws ArithmeticException
long argument;
throwing an exception if the value overflows an int.value - the long valueArithmeticException - if the argument overflows an intpublic static short toUInt8(long value)
throws ArithmeticException
long argument;
throwing an exception if the value overflows an unsigned byte (0xFF).value - the long valueArithmeticException - if the argument overflows an unsigned bytepublic static int toUInt16(long value)
throws ArithmeticException
long argument;
throwing an exception if the value overflows an unsigned short (0xFFFF).value - the long valueArithmeticException - if the argument overflows an unsigned shortpublic static int toUInt31(long value)
throws ArithmeticException
long argument;
throwing an exception if the value overflows an unsigned 31 bit value (0x7FFFFFFFL).value - the long valueArithmeticException - if the argument overflows an unsigned intpublic static long toUInt32(long value)
throws ArithmeticException
long argument;
throwing an exception if the value overflows an unsigned int (0xFFFFFFFFL).value - the long valueArithmeticException - if the argument overflows an unsigned intpublic static long agitate(long l)
l - the long value to be agitatedpublic static long hash64(long l0)
l0 - to hash@Deprecated public static long hash64(long l0, long l1)
l0 - to hashl1 - to hashpublic static long divideRoundUp(long dividend,
long divisor)
dividend by divisor, if division is not integral the result is rounded up.
Examples: divideRoundUp(10, 5) == 2, divideRoundUp(11, 5) == 3,
divideRoundUp(-10, 5) == -2, divideRoundUp(-11, 5) == -3.public static long tens(int decimalPlaces)
decimalPlaces - the number of decimal placesIllegalArgumentException - if the decimal places are less than 0 or greater than or equal to 19public static int digits(long num)
num - the number to count the digits ofpublic static long fives(int decimalPlaces)
decimalPlaces - the number of decimal placespublic static boolean same(double a,
double b)
a - the first double valueb - the second double valuepublic static boolean same(float a,
float b)
a - the first float valueb - the second float valuepublic static int hash(Object o)
public static double asDouble(long value,
int exponent,
boolean negative,
int decimalPlaces)
value - The integer valueexponent - The exponentnegative - Whether it is negative or notdecimalPlaces - The number of decimal placespublic static double add(long a,
long b,
long c)
Copyright © 2023. All rights reserved.