Package net.apartium.cocoabeans
Class Mathf
java.lang.Object
net.apartium.cocoabeans.Mathf
A utility class providing mathematical functions.
Currently includes linear interpolation (lerp) methods for various primitive types.
- Since:
- 0.0.39
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doublelerp(double a, double b, double t) Performs linear interpolation between twodoublevalues.static floatlerp(float a, float b, float t) Performs linear interpolation between twofloatvalues.static intlerp(int a, int b, float t) Performs linear interpolation between twointvalues.static longlerp(long a, long b, float t) Performs linear interpolation between twolongvalues.static doublelog4(long x) Computes the base-4 logarithm of the given value.static longnextPowerOfFour(long x) Returns the next power of four greater than or equal to the given value.
-
Field Details
-
LOG4_AS_VALUE
@AvailableSince("0.0.46") public static final double LOG4_AS_VALUE
-
-
Method Details
-
lerp
public static int lerp(int a, int b, float t) Performs linear interpolation between twointvalues.- Parameters:
a- the start valueb- the end valuet- the interpolation factor, typically in the range [0.0, 1.0]- Returns:
- the interpolated value, cast to
int
-
lerp
public static long lerp(long a, long b, float t) Performs linear interpolation between twolongvalues.- Parameters:
a- the start valueb- the end valuet- the interpolation factor, typically in the range [0.0, 1.0]- Returns:
- the interpolated value, cast to
long
-
lerp
public static float lerp(float a, float b, float t) Performs linear interpolation between twofloatvalues.- Parameters:
a- the start valueb- the end valuet- the interpolation factor, typically in the range [0.0f, 1.0f]- Returns:
- the interpolated
floatvalue
-
lerp
public static double lerp(double a, double b, double t) Performs linear interpolation between twodoublevalues.- Parameters:
a- the start valueb- the end valuet- the interpolation factor, typically in the range [0.0, 1.0]- Returns:
- the interpolated
doublevalue
-
nextPowerOfFour
@AvailableSince("0.0.46") public static long nextPowerOfFour(long x) Returns the next power of four greater than or equal to the given value.If
xis less than or equal to 1, returns 1. Ifxis too large to fit in a long, returns 0 as an overflow guard.- Parameters:
x- the input value- Returns:
- the next power of four greater than or equal to
x, or 0 if overflow
-
log4
@AvailableSince("0.0.46") public static double log4(long x) Computes the base-4 logarithm of the given value.Uses the natural logarithm and divides by the precomputed value of log(4).
- Parameters:
x- the value to compute the logarithm for- Returns:
- the base-4 logarithm of
x
-