public final class Maths extends Object
Modifier and Type | Method and Description |
---|---|
static long |
agitate(long l) |
static double |
ceilN(double d,
double digits) |
static double |
ceilN(double d,
int digits) |
static int |
digits(long num) |
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) |
static double |
floorN(double d,
double digits) |
static double |
floorN(double d,
int digits) |
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) |
static int |
hash32(long l0) |
static int |
hash32(@NotNull String s) |
static int |
hash32(@NotNull StringBuilder s) |
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)
A simple hashing algorithm for a 128-bit value
|
static long |
hash64(@NotNull String s) |
static long |
hash64(@NotNull StringBuilder s) |
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) |
static boolean |
same(float a,
float b) |
static long |
tens(int decimalPlaces) |
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)
public static double floorN(double d, int digits)
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)
public static int hash32(@NotNull @NotNull CharSequence cs)
public static int hash32(@NotNull @NotNull String s)
public static int hash32(@NotNull @NotNull StringBuilder s)
public static int hash32(long l0)
public static long hash64(@Nullable @Nullable CharSequence cs)
public static long hash64(@NotNull @NotNull String s)
public static long hash64(@NotNull @NotNull StringBuilder s)
public 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)
public static long hash64(long l0)
l0
- to hashpublic 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)
public static int digits(long num)
public static long fives(int decimalPlaces)
public static boolean same(double a, double b)
public static boolean same(float a, float b)
public static int hash(Object o)
Copyright © 2022. All rights reserved.