Class Mathf

java.lang.Object
net.apartium.cocoabeans.Mathf

@AvailableSince("0.0.39") public class Mathf extends Object
A utility class providing mathematical functions.

Currently includes linear interpolation (lerp) methods for various primitive types.

Since:
0.0.39
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    lerp(double a, double b, double t)
    Performs linear interpolation between two double values.
    static float
    lerp(float a, float b, float t)
    Performs linear interpolation between two float values.
    static int
    lerp(int a, int b, float t)
    Performs linear interpolation between two int values.
    static long
    lerp(long a, long b, float t)
    Performs linear interpolation between two long values.
    static double
    log4(long x)
    Computes the base-4 logarithm of the given value.
    static long
    Returns the next power of four greater than or equal to the given value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 two int values.
      Parameters:
      a - the start value
      b - the end value
      t - 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 two long values.
      Parameters:
      a - the start value
      b - the end value
      t - 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 two float values.
      Parameters:
      a - the start value
      b - the end value
      t - the interpolation factor, typically in the range [0.0f, 1.0f]
      Returns:
      the interpolated float value
    • lerp

      public static double lerp(double a, double b, double t)
      Performs linear interpolation between two double values.
      Parameters:
      a - the start value
      b - the end value
      t - the interpolation factor, typically in the range [0.0, 1.0]
      Returns:
      the interpolated double value
    • 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 x is less than or equal to 1, returns 1. If x is 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