Class NumberMath
java.lang.Object
io.github.syst3ms.skriptparser.util.math.NumberMath
Utilities for various math operations using the generic
Number type
I do not claim ownership of this code, it is the intellectual property of @obermuhlner.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Numberstatic Numberstatic Numberstatic Numberstatic Numberstatic Numberstatic Numberstatic Numberstatic Numberstatic booleanisPrime(BigInteger number) Checks if a given BigInteger is prime.static Numberstatic Numberstatic Numberstatic Numberrandom(Number lower, Number upper, boolean inclusive, ThreadLocalRandom random) Computes a random number between the two given bounds The return type is related to the parameter types in the following way : Two bounds of the same type will return a result of the same type If one of the bounds is aBigDecimal, so will be the result If one of the bounds is aBigIntegerand the other is aDouble, the result will be aBigDecimalIf one of the bounds is aBigIntegerand the other is aLong, the result will be aBigIntegerOtherwise (i.e one of the bounds is alongand the other adouble), the result will be adoublestatic BigDecimalrandomBigDecimal(BigDecimal lower, BigDecimal upper, ThreadLocalRandom random) static BigIntegerrandomBigInteger(BigInteger lower, BigInteger upper, ThreadLocalRandom random) static Numberstatic Numberstatic Numberstatic Numberstatic Numberstatic Number
-
Constructor Details
-
NumberMath
public NumberMath()
-
-
Method Details
-
abs
-
negate
-
sqrt
-
ln
-
log
-
factorial
-
floor
-
ceil
-
round
-
sin
-
cos
-
tan
-
asin
-
acos
-
atan
-
sinh
-
cosh
-
tanh
-
isPrime
Checks if a given BigInteger is prime. The certainty of this check is always 100%- Parameters:
number- the number to check- Returns:
- whether or not this number is a prime
-
random
public static Number random(Number lower, Number upper, boolean inclusive, ThreadLocalRandom random) Computes a random number between the two given bounds The return type is related to the parameter types in the following way :- Two bounds of the same type will return a result of the same type
- If one of the bounds is a
BigDecimal, so will be the result - If one of the bounds is a
BigIntegerand the other is aDouble, the result will be aBigDecimal - If one of the bounds is a
BigIntegerand the other is aLong, the result will be aBigInteger - Otherwise (i.e one of the bounds is a
longand the other adouble), the result will be adouble
- Parameters:
lower- the lower boundupper- the upper boundinclusive- whether the bounds are exclusive or not (skript-parser defaults to true in its implementation)random- theThreadLocalRandominstance used- Returns:
- a random
Numberbetween the two given bounds
-
randomBigInteger
public static BigInteger randomBigInteger(BigInteger lower, BigInteger upper, ThreadLocalRandom random) - Parameters:
lower- the lower boundupper- the upper bound- Returns:
- a random
BigIntegerbetweenlower(inclusive) andupper(exclusive)
-
randomBigDecimal
public static BigDecimal randomBigDecimal(BigDecimal lower, BigDecimal upper, ThreadLocalRandom random) - Parameters:
lower- the lower boundupper- the upper bound- Returns:
- a random
BigDecimalbetweenlower(inclusive) andupper(exclusive)
-
getCachedPrimes
-