mikera.util
Class Maths
- java.lang.Object
-
- mikera.util.Maths
-
public final class Maths extends java.lang.ObjectHelpful maths functions Focus on using floats rather than doubles for speed
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleEmathematical constant estatic doubleHALF_PIstatic doublePIMathematical constant Pi = 3.1415926...static doubleQUARTER_PIstatic doubleROOT_THREEstatic doubleROOT_TWOstatic doubleTAUMathematical constant Tau = 2 * Pistatic doubleTWO_PI
-
Constructor Summary
Constructors Constructor and Description Maths()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doublebound(double v, double min, double max)Bound a value within a given rangestatic floatbound(float v, float min, float max)Bound a value within a given rangestatic intbound(int v, int min, int max)Bound a value within a given rangestatic intclampToInteger(double value, int min, int max)Clamp a double value to an integer rangestatic intclampToInteger(float value, int min, int max)Clamp a float value to an integer rangestatic doublefrac(double a)Return the (always non-negative) fractional part of a numberstatic floatfrac(float a)Return the (always non-negative) fractional part of a numberstatic doubleinverseLogistic(double y)static doublelerp(double t, double a, double b)Linear interpolation between a and bstatic doublelogistic(double x)Standard logistic functionstatic doublelogisticDerivative(double x)static doublemax(double a, double b, double c)Return the maximum of three valuesstatic floatmax(float a, float b)Return the maximum of two numbersstatic floatmax(float a, float b, float c)Return the maximum of three valuesstatic floatmax(float a, float b, float c, float d)Return the maximum of four valuesstatic intmax(int a, int b)Return the maximum of two numbersstatic intmax(int a, int b, int c)Return the maximum of three numbersstatic floatmiddle(float a, float b, float c)Return the middle value of 3 numbers Can use faster "bound" method if parameters 2 and 3 are known to be in orderstatic intmiddle(int a, int b, int c)Return the middle value of 3 numbers Can use faster "bound" method if first and last parameters are in orderstatic doublemin(double a, double b, double c)Return the minimum of three valuesstatic floatmin(float a, float b)Return the minimum of two numbersstatic floatmin(float a, float b, float c)Return the minimum of three valuesstatic floatmin(float a, float b, float c, float d)Return the minimum of four valuesstatic intmin(int a, int b)Return the minimum of two numbersstatic intmin(int a, int b, int c)Return the minimum of three numbersstatic doublemod(double num, double div)Double mod function with fractional divisorstatic intmod(int number, int divisor)Integer modulus functionstatic longmod(long number, long divisor)Long modulus functionstatic intmodPower32Bit(int x, int pow)Returns (x^pow) mod (2^32) as an intstatic booleannotNearZero(double x)Tests whether a value is near zero, to a default tolerance levelstatic longquantize(long increase, long boundary, long base)Detects the number of times that boundary is passed when adding increase to basestatic introundDown(double x)Rounds down (integer floor) of a double valuestatic introundDown(float x)Round down to next smallest integer (towards negative infinity)static introundUp(double x)Round up to next integerstatic introundUp(float x)Round up to next integerstatic introundUp(java.lang.Number x)Round up to next integerstatic intsign(double x)Return the sign of a double valuestatic intsign(float x)Return the sign of a float valuestatic intsign(int a)Return the sign of an int valuestatic intsign(long a)Return the sign of a long valuestatic doublesoftMaximum(double x, double y)Soft maximum functionstatic doublesoftplus(double x)static doublesqrt(double a)static floatsqrt(float a)static intsquare(byte b)Return the square of a numberstatic doublesquare(double x)Return the square of a numberstatic floatsquare(float x)Return the square of a numberstatic intsquare(int x)Return the square of a numberstatic doubletanhDerivative(double x)static doubletanhScaled(double x)static doubletanhScaledDerivative(double x)static doubletriangleWave(double x)Triangle wave with wavelength 1.0, and range 0.0 - 1.0
-
-
-
Field Detail
-
ROOT_TWO
public static final double ROOT_TWO
-
ROOT_THREE
public static final double ROOT_THREE
-
E
public static final double E
mathematical constant e- See Also:
- Constant Field Values
-
PI
public static final double PI
Mathematical constant Pi = 3.1415926...- See Also:
- Constant Field Values
-
TWO_PI
public static final double TWO_PI
- See Also:
- Constant Field Values
-
TAU
public static final double TAU
Mathematical constant Tau = 2 * Pi- See Also:
- Constant Field Values
-
HALF_PI
public static final double HALF_PI
- See Also:
- Constant Field Values
-
QUARTER_PI
public static final double QUARTER_PI
- See Also:
- Constant Field Values
-
-
Method Detail
-
sqrt
public static float sqrt(float a)
-
sqrt
public static double sqrt(double a)
-
clampToInteger
public static int clampToInteger(double value, int min, int max)Clamp a double value to an integer range
-
clampToInteger
public static int clampToInteger(float value, int min, int max)Clamp a float value to an integer range
-
lerp
public static final double lerp(double t, double a, double b)Linear interpolation between a and b
-
middle
public static int middle(int a, int b, int c)Return the middle value of 3 numbers Can use faster "bound" method if first and last parameters are in order
-
middle
public static float middle(float a, float b, float c)Return the middle value of 3 numbers Can use faster "bound" method if parameters 2 and 3 are known to be in order
-
sign
public static int sign(double x)
Return the sign of a double value
-
sign
public static int sign(float x)
Return the sign of a float value
-
sign
public static final int sign(int a)
Return the sign of an int value
-
sign
public static int sign(long a)
Return the sign of a long value
-
mod
public static int mod(int number, int divisor)Integer modulus function- Parameters:
n- numberd- divisor- Returns:
-
mod
public static long mod(long number, long divisor)Long modulus function- Parameters:
n- numberd- divisor- Returns:
-
quantize
public static long quantize(long increase, long boundary, long base)Detects the number of times that boundary is passed when adding increase to base- Parameters:
increase-boundary-base-- Returns:
-
min
public static double min(double a, double b, double c)Return the minimum of three values
-
max
public static double max(double a, double b, double c)Return the maximum of three values
-
min
public static float min(float a, float b, float c)Return the minimum of three values
-
max
public static float max(float a, float b, float c)Return the maximum of three values
-
min
public static final float min(float a, float b, float c, float d)Return the minimum of four values
-
max
public static final float max(float a, float b, float c, float d)Return the maximum of four values
-
min
public static int min(int a, int b)Return the minimum of two numbers
-
max
public static int max(int a, int b)Return the maximum of two numbers
-
min
public static float min(float a, float b)Return the minimum of two numbers
-
max
public static float max(float a, float b)Return the maximum of two numbers
-
min
public static int min(int a, int b, int c)Return the minimum of three numbers
-
max
public static int max(int a, int b, int c)Return the maximum of three numbers
-
logistic
public static double logistic(double x)
Standard logistic function- Parameters:
x-- Returns:
-
softplus
public static double softplus(double x)
-
tanhScaled
public static double tanhScaled(double x)
-
tanhScaledDerivative
public static double tanhScaledDerivative(double x)
-
inverseLogistic
public static double inverseLogistic(double y)
-
logisticDerivative
public static double logisticDerivative(double x)
-
tanhDerivative
public static double tanhDerivative(double x)
-
frac
public static float frac(float a)
Return the (always non-negative) fractional part of a number
-
frac
public static double frac(double a)
Return the (always non-negative) fractional part of a number
-
square
public static int square(byte b)
Return the square of a number
-
square
public static int square(int x)
Return the square of a number
-
square
public static float square(float x)
Return the square of a number
-
square
public static double square(double x)
Return the square of a number
-
roundUp
public static int roundUp(double x)
Round up to next integer
-
roundUp
public static int roundUp(java.lang.Number x)
Round up to next integer
-
roundUp
public static int roundUp(float x)
Round up to next integer
-
roundDown
public static int roundDown(double x)
Rounds down (integer floor) of a double value
-
roundDown
public static int roundDown(float x)
Round down to next smallest integer (towards negative infinity)
-
softMaximum
public static double softMaximum(double x, double y)Soft maximum function
-
bound
public static final double bound(double v, double min, double max)Bound a value within a given range
-
bound
public static final float bound(float v, float min, float max)Bound a value within a given range
-
bound
public static final int bound(int v, int min, int max)Bound a value within a given range
-
modPower32Bit
public static int modPower32Bit(int x, int pow)Returns (x^pow) mod (2^32) as an int
-
notNearZero
public static boolean notNearZero(double x)
Tests whether a value is near zero, to a default tolerance level
-
mod
public static double mod(double num, double div)Double mod function with fractional divisor
-
triangleWave
public static double triangleWave(double x)
Triangle wave with wavelength 1.0, and range 0.0 - 1.0
-
-
DMelt 3.0 © DataMelt by jWork.ORG