Package org.meeuw.math
Class Utils
- java.lang.Object
-
- org.meeuw.math.Utils
-
public final class Utils extends Object
- Author:
- Michiel Meeuwissen
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isPrime(int n)
Simple prime test.static int
leastSignificantBit(double doubleValue)
Given a double value, returns the bit the power of 2 exponent that the least significant bit in the IEEE 754 representation of the double represents.static int
log10(double d)
A crude order of magnitude implemention This is likeMath.log10(Mat.abs(d))
static int
log10(long l)
A crude order of magnitude implemention This is likeMath.log10(Mat.abs(l))
static ChronoUnit
orderOfMagnitude(Duration stddev)
static long
positivePow(@javax.validation.constraints.NotNull long base, @javax.validation.constraints.Min(0L) int i)
Returns base to the power i, a utility in java.lang.Math for that lacks.static long
positivePow10(@javax.validation.constraints.Min(0L) int i)
Returns 10 to the power i, a utility in java.lang.Math for that lacks.static double
pow(double base, int i)
Returns base to the power i, a utility in java.lang.Math for that lacks.static double
pow(int base, int i)
Returns base to the power i, a utility in java.lang.Math for that lacks.static double
pow10(int i)
Returns 10 to the power i, a utility in java.lang.Math for that lacks.static double
pow2(int i)
Returns 10 to the power i, a utility in java.lang.Math for that lacks.static Duration
round(Duration duration, ChronoUnit order)
static Instant
round(Instant instant, ChronoUnit order)
static Stream<int[]>
stream(int length)
Returns an infinite stream of integer arrays of given length It will start with an array with only zeros.static <T extends Enum<T>>
StringtoString(T[] values, int[] basic)
Given an array of enums, and a array of integers, interpret the second array as exponents for the first one, and create a string representation of that using superscript notation.static double
uncertaintyForDouble(double doubleValue)
-
-
-
Field Detail
-
PI
public static final String PI
1000 decimals of pi- See Also:
- Constant Field Values
-
e
public static final String e
- See Also:
- Constant Field Values
-
-
Method Detail
-
pow10
public static double pow10(int i)
Returns 10 to the power i, a utility in java.lang.Math for that lacks.
-
pow2
public static double pow2(int i)
Returns 10 to the power i, a utility in java.lang.Math for that lacks.
-
pow
public static double pow(int base, int i)
Returns base to the power i, a utility in java.lang.Math for that lacks.
-
pow
public static double pow(double base, int i)
Returns base to the power i, a utility in java.lang.Math for that lacks.
-
positivePow10
public static long positivePow10(@Min(0L) @javax.validation.constraints.Min(0L) int i)
Returns 10 to the power i, a utility in java.lang.Math for that lacks.- See Also:
positivePow(long, int)
-
positivePow
public static long positivePow(@NotNull @javax.validation.constraints.NotNull long base, @Min(0L) @javax.validation.constraints.Min(0L) int i)
Returns base to the power i, a utility in java.lang.Math for that lacks. This is more exact thanMath.pow(double, double)
(though probably not faster)
-
log10
public static int log10(double d)
A crude order of magnitude implemention This is likeMath.log10(Mat.abs(d))
-
log10
public static int log10(long l)
A crude order of magnitude implemention This is likeMath.log10(Mat.abs(l))
-
orderOfMagnitude
public static ChronoUnit orderOfMagnitude(Duration stddev)
-
round
public static Duration round(Duration duration, ChronoUnit order)
-
round
public static Instant round(Instant instant, ChronoUnit order)
-
stream
public static Stream<int[]> stream(int length)
Returns an infinite stream of integer arrays of given length It will start with an array with only zeros. Then it will return array filled with all possible combinations of -1, 0, 1, then with all possibles arrays with only -2, -1, 0, 1, 2 and so on.
-
toString
public static <T extends Enum<T>> String toString(T[] values, int[] basic)
Given an array of enums, and a array of integers, interpret the second array as exponents for the first one, and create a string representation of that using superscript notation.
-
leastSignificantBit
public static int leastSignificantBit(double doubleValue)
Given a double value, returns the bit the power of 2 exponent that the least significant bit in the IEEE 754 representation of the double represents. pow(2,) is an estimate of the 'uncertainty' in this double. More precision it simply cannot represent.
-
uncertaintyForDouble
public static double uncertaintyForDouble(double doubleValue)
-
isPrime
public static boolean isPrime(int n)
Simple prime test. 6k ± 1 optimization only. Not suitable for (very) large numbers.
-
-