Documentation of 'mikera.util.Maths' Java class
Maths
mikera.util

Class Maths



  • public final class Maths
    extends java.lang.Object
    Helpful maths functions Focus on using floats rather than doubles for speed
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static double E
      mathematical constant e
      static double HALF_PI 
      static double PI
      Mathematical constant Pi = 3.1415926...
      static double QUARTER_PI 
      static double ROOT_THREE 
      static double ROOT_TWO 
      static double TAU
      Mathematical constant Tau = 2 * Pi
      static double TWO_PI 
    • Constructor Summary

      Constructors 
      Constructor and Description
      Maths() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static double bound(double v, double min, double max)
      Bound a value within a given range
      static float bound(float v, float min, float max)
      Bound a value within a given range
      static int bound(int v, int min, int max)
      Bound a value within a given range
      static int clampToInteger(double value, int min, int max)
      Clamp a double value to an integer range
      static int clampToInteger(float value, int min, int max)
      Clamp a float value to an integer range
      static double frac(double a)
      Return the (always non-negative) fractional part of a number
      static float frac(float a)
      Return the (always non-negative) fractional part of a number
      static double inverseLogistic(double y) 
      static double lerp(double t, double a, double b)
      Linear interpolation between a and b
      static double logistic(double x)
      Standard logistic function
      static double logisticDerivative(double x) 
      static double max(double a, double b, double c)
      Return the maximum of three values
      static float max(float a, float b)
      Return the maximum of two numbers
      static float max(float a, float b, float c)
      Return the maximum of three values
      static float max(float a, float b, float c, float d)
      Return the maximum of four values
      static int max(int a, int b)
      Return the maximum of two numbers
      static int max(int a, int b, int c)
      Return the maximum of three numbers
      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
      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
      static double min(double a, double b, double c)
      Return the minimum of three values
      static float min(float a, float b)
      Return the minimum of two numbers
      static float min(float a, float b, float c)
      Return the minimum of three values
      static float min(float a, float b, float c, float d)
      Return the minimum of four values
      static int min(int a, int b)
      Return the minimum of two numbers
      static int min(int a, int b, int c)
      Return the minimum of three numbers
      static double mod(double num, double div)
      Double mod function with fractional divisor
      static int mod(int number, int divisor)
      Integer modulus function
      static long mod(long number, long divisor)
      Long modulus function
      static int modPower32Bit(int x, int pow)
      Returns (x^pow) mod (2^32) as an int
      static boolean notNearZero(double x)
      Tests whether a value is near zero, to a default tolerance level
      static long quantize(long increase, long boundary, long base)
      Detects the number of times that boundary is passed when adding increase to base
      static int roundDown(double x)
      Rounds down (integer floor) of a double value
      static int roundDown(float x)
      Round down to next smallest integer (towards negative infinity)
      static int roundUp(double x)
      Round up to next integer
      static int roundUp(float x)
      Round up to next integer
      static int roundUp(java.lang.Number x)
      Round up to next integer
      static int sign(double x)
      Return the sign of a double value
      static int sign(float x)
      Return the sign of a float value
      static int sign(int a)
      Return the sign of an int value
      static int sign(long a)
      Return the sign of a long value
      static double softMaximum(double x, double y)
      Soft maximum function
      static double softplus(double x) 
      static double sqrt(double a) 
      static float sqrt(float a) 
      static int square(byte b)
      Return the square of a number
      static double square(double x)
      Return the square of a number
      static float square(float x)
      Return the square of a number
      static int square(int x)
      Return the square of a number
      static double tanhDerivative(double x) 
      static double tanhScaled(double x) 
      static double tanhScaledDerivative(double x) 
      static double triangleWave(double x)
      Triangle wave with wavelength 1.0, and range 0.0 - 1.0
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Maths

        public Maths()
    • 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 - number
        d - divisor
        Returns:
      • mod

        public static long mod(long number,
                               long divisor)
        Long modulus function
        Parameters:
        n - number
        d - 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

You see the box below because you did not login.