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)
Rounds up the given value to the nearest higher number with specified decimal places.
|
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)
Rounds down the given value to the nearest lower number with specified decimal places.
|
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 long |
hash64(@Nullable CharSequence cs) |
static long |
hash64(long l0)
A simple hashing algorithm for a 64-bit value
|
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)
Checks if a number is a power of two.
|
static int |
nextPower2(int n,
int min)
Returns the next power of two greater than or equal to the given number, with a specified minimum.
|
static long |
nextPower2(long n,
long min)
Returns the next power of two greater than or equal to the given number, with a specified minimum.
|
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)
d - the value to ceildigits - number of decimal placespublic static double floorN(double d,
double digits)
d - the value to floordigits - number of decimal placespublic 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 - the number to find the next power of two formin - the minimum power of two to return if n is less than minIllegalArgumentException - if the provided min value is not a positive power of twopublic static long nextPower2(long n,
long min)
throws IllegalArgumentException
n - the number to find the next power of two formin - the minimum power of two to return if n is less than minIllegalArgumentException - if the provided min value is not a positive power of twopublic static boolean isPowerOf2(long n)
n - the number to checkpublic 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 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 © 2024. All rights reserved.