public class MathUtil extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
INFINITE_STRING |
static double |
POW2_16_DOUBLE |
static float |
POW2_16_FLOAT |
static double |
POW2_32_DOUBLE |
static float |
POW2_32_FLOAT |
static double |
POW2_64_DOUBLE |
static float |
POW2_64_FLOAT |
static double |
POW2_8_DOUBLE |
static float |
POW2_8_FLOAT |
Constructor and Description |
---|
MathUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
add(double[] array,
double value)
Add the the specified value to all elements in an array
|
static void |
add(float[] array,
float value)
Add the the specified value to all elements in an array
|
static double |
closest(double value,
double[] source)
Return the value in
source which is the closest to value Returns
0 if source is null or empty. |
static double |
cubicRoot(double value)
Calculate the cubic root of the specified value.
|
static void |
divide(double[] array,
double value)
Divides all elements in an array by the specified value
|
static void |
divide(float[] array,
float value)
Divides all elements in an array by the specified value
|
static double |
formatDegreeAngle(double angle)
Format the specified degree angle to stay in [0..360[ range
|
static double |
formatDegreeAngle2(double angle)
Format the specified degree angle to stay in [-180..180] range
|
static double |
formatRadianAngle(double angle)
Format the specified degree angle to stay in [0..2PI[ range
|
static double |
formatRadianAngle2(double angle)
Format the specified degree angle to stay in [-PI..PI] range
|
static double |
frac(double value) |
static java.lang.String |
getBytesString(double value)
Deprecated.
please use
UnitUtil.getBytesString(double) instead. |
static void |
log(double[] array)
Replace all values in the array by their logarithm
Be careful, all values should be >0 values |
static void |
log(float[] array)
Replace all values in the array by their logarithm
Be careful, all values should be >0 values |
static void |
madd(double[] array,
double mulValue,
double addValue)
Multiply and add all elements in an array by the specified values
|
static void |
madd(float[] array,
float mulValue,
float addValue)
Multiply and add all elements in an array by the specified values
|
static int |
max(byte[] array,
boolean signed)
Deprecated.
use
ArrayMath.max(byte[], boolean) instead |
static double |
max(double[] array)
Deprecated.
use
ArrayMath.max(double[]) instead |
static float |
max(float[] array)
Deprecated.
use
ArrayMath.max(float[]) instead |
static long |
max(int[] array,
boolean signed)
Deprecated.
use
ArrayMath.max(int[], boolean) instead |
static double |
max(java.lang.Object array,
boolean signed)
Deprecated.
use
ArrayMath.max(Object, boolean) instead |
static int |
max(short[] array,
boolean signed)
Deprecated.
use
ArrayMath.max(short[], boolean) instead |
static int |
min(byte[] array,
boolean signed)
Deprecated.
use
ArrayMath.min(byte[], boolean) instead |
static double |
min(double[] array)
Deprecated.
use
ArrayMath.min(double[]) instead |
static float |
min(float[] array)
Deprecated.
use
ArrayMath.min(float[]) instead |
static long |
min(int[] array,
boolean signed)
Deprecated.
use
ArrayMath.min(int[], boolean) instead |
static double |
min(java.lang.Object array,
boolean signed)
Deprecated.
use
ArrayMath.min(Object, boolean) instead |
static int |
min(short[] array,
boolean signed)
Deprecated.
use
ArrayMath.min(short[], boolean) instead |
static void |
mul(double[] array,
double value)
Multiply all elements in an array by the specified value
|
static void |
mul(float[] array,
float value)
Multiply all elements in an array by the specified value
|
static double |
nextMultiple(double value,
double mul)
Return the next multiple of "mul" for the specified value
nextMultiple(200, 64) = 256
|
static double |
nextPow10(double value)
Return the next power of 10 for the specified value
nextPow10(0.0067) = 0.01
nextPow10(-28.7) = -10
|
static long |
nextPow2(long value)
Return the next power of 2 for the specified value
nextPow2(17) = 32
nextPow2(16) = 32
nextPow2(-12) = -8
nextPow2(-8) = -4
|
static long |
nextPow2Mask(long value)
Return the next power of 2 mask for the specified value
nextPow2Mask(17) = 31
nextPow2Mask(16) = 31
nextPow2Mask(-12) = -8
nextPow2Mask(-8) = -4
|
static void |
normalize(double[] array)
Normalize an array
|
static void |
normalize(float[] array)
Normalize an array
|
static double |
prevMultiple(double value,
double mul)
Return the previous multiple of "mul" for the specified value
prevMultiple(200, 64) = 192
|
static double |
prevPow10(double value)
Return the previous power of 10 for the specified value
prevPow10(0.0067) = 0.001
prevPow10(-28.7) = -100
|
static long |
prevPow2(long value)
Return the previous power of 2 for the specified value
prevPow2(17) = 16
prevPow2(16) = 8
prevPow2(-12) = -16
prevPow2(-8) = -16
|
static double |
round(double d,
int numDecimal)
Round specified value to specified number of decimal.
|
static double |
roundSignificant(double d,
int numDigit)
Round specified value to specified number of significant digit.
|
static double |
roundSignificant(double d,
int numDigit,
boolean keepInteger)
Round specified value to specified number of significant digit.
|
public static final java.lang.String INFINITE_STRING
public static final double POW2_8_DOUBLE
public static final float POW2_8_FLOAT
public static final double POW2_16_DOUBLE
public static final float POW2_16_FLOAT
public static final double POW2_32_DOUBLE
public static final float POW2_32_FLOAT
public static final double POW2_64_DOUBLE
public static final float POW2_64_FLOAT
public MathUtil()
@Deprecated public static java.lang.String getBytesString(double value)
UnitUtil.getBytesString(double)
instead.public static double frac(double value)
public static void normalize(float[] array)
array
- elements to normalizepublic static void normalize(double[] array)
array
- elements to normalizepublic static void log(double[] array)
array
- elements to logarithmpublic static void log(float[] array)
array
- elements to logarithmpublic static void add(double[] array, double value)
array
- elements to modifyvalue
- public static void add(float[] array, float value)
array
- elements to modifyvalue
- public static void madd(double[] array, double mulValue, double addValue)
array
- elements to modifymulValue
- addValue
- public static void madd(float[] array, float mulValue, float addValue)
array
- elements to modifymulValue
- addValue
- public static void mul(double[] array, double value)
array
- elements to modifyvalue
- value to multiply bypublic static void mul(float[] array, float value)
array
- elements to modifyvalue
- value to multiply bypublic static void divide(double[] array, double value)
array
- elements to modifyvalue
- value used as divisorpublic static void divide(float[] array, float value)
array
- elements to modifyvalue
- value used as divisor@Deprecated public static double min(java.lang.Object array, boolean signed)
ArrayMath.min(Object, boolean)
instead@Deprecated public static int min(byte[] array, boolean signed)
ArrayMath.min(byte[], boolean)
instead@Deprecated public static int min(short[] array, boolean signed)
ArrayMath.min(short[], boolean)
instead@Deprecated public static long min(int[] array, boolean signed)
ArrayMath.min(int[], boolean)
instead@Deprecated public static float min(float[] array)
ArrayMath.min(float[])
instead@Deprecated public static double min(double[] array)
ArrayMath.min(double[])
instead@Deprecated public static double max(java.lang.Object array, boolean signed)
ArrayMath.max(Object, boolean)
instead@Deprecated public static int max(byte[] array, boolean signed)
ArrayMath.max(byte[], boolean)
instead@Deprecated public static int max(short[] array, boolean signed)
ArrayMath.max(short[], boolean)
instead@Deprecated public static long max(int[] array, boolean signed)
ArrayMath.max(int[], boolean)
instead@Deprecated public static float max(float[] array)
ArrayMath.max(float[])
instead@Deprecated public static double max(double[] array)
ArrayMath.max(double[])
insteadpublic static double roundSignificant(double d, int numDigit, boolean keepInteger)
public static double roundSignificant(double d, int numDigit)
public static double round(double d, int numDecimal)
public static double prevMultiple(double value, double mul)
value
- mul
- public static double nextMultiple(double value, double mul)
value
- mul
- public static long nextPow2(long value)
value
- public static long nextPow2Mask(long value)
value
- public static long prevPow2(long value)
value
- public static double nextPow10(double value)
value
- public static double prevPow10(double value)
value
- public static double formatDegreeAngle(double angle)
public static double formatDegreeAngle2(double angle)
public static double formatRadianAngle(double angle)
public static double formatRadianAngle2(double angle)
public static double closest(double value, double[] source)
source
which is the closest to value
Returns
0
if source is null or empty.public static double cubicRoot(double value)