Documentation of 'jhplot.math.MathUtilsd' Java class.
MathUtilsd
jhplot.math

Class MathUtilsd



  • public final class MathUtilsd
    extends java.lang.Object
    Utility and fast math functions.

    Thanks to Riven on JavaGaming.org for the basis of sin/cos/atan2/floor/ceil. Typical accurracy is E-05, but it can be changed.

    • Constructor Summary

      Constructors 
      Constructor and Description
      MathUtilsd() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static double acos_v1(double x)
      Arc cos approximation
      static double acos_v2(double x) 
      static double acos(double x)
      Returns the arc cosine in radians from a lookup table.
      static double asin_core(double x) 
      static double atan2(double y, double x)
      Returns atan2 in radians from a lookup table.
      static int ceil(double x)
      Returns the smallest integer greater than or equal to the specified double.
      static int ceilPositive(double x)
      Returns the smallest integer greater than or equal to the specified double.
      static double clamp(double value, double min, double max) 
      static float clamp(float value, float min, float max) 
      static int clamp(int value, int min, int max) 
      static short clamp(short value, short min, short max) 
      static double cos_core(double x) 
      static double cos(double radians)
      Returns the cosine in radians from a lookup table.
      static double cosDeg(double degrees)
      Returns the cosine in radians from a lookup table.
      static int floor(double x)
      Returns the largest integer less than or equal to the specified double.
      static int floorPositive(double x)
      Returns the largest integer less than or equal to the specified double.
      static void initialize() 
      static boolean isEqual(double a, double b)
      Returns true if a is nearly equal to b.
      static boolean isEqual(double a, double b, double tolerance)
      Returns true if a is nearly equal to b.
      static boolean isPowerOfTwo(int value) 
      static boolean isZero(double value)
      Returns true if the value is zero (using the default tolerance as upper bound)
      static boolean isZero(double value, double tolerance)
      Returns true if the value is zero.
      static double lint(double x, double x0, double x1, double y0, double y1)
      Lineal interpolation.
      static float lint(float x, float x0, float x1, float y0, float y1)
      Lineal interpolation.
      static int nextPowerOfTwo(int value)
      Returns the next power of two.
      static double rint_v2(double x) 
      static int round(double x)
      Returns the closest integer to the specified double.
      static int roundPositive(double x)
      Returns the closest integer to the specified double.
      static double sin_core(double x) 
      static double sin_v2(double x) 
      static double sin(double radians)
      Returns the sine in radians from a lookup table.
      static double sinDeg(double degrees)
      Returns the sine in radians from a lookup table.
      static double sqrt(double value)
      Fast sqrt method.
      • Methods inherited from class java.lang.Object

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

      • MathUtilsd

        public MathUtilsd()
    • Method Detail

      • initialize

        public static void initialize()
      • sin

        public static final double sin(double radians)
        Returns the sine in radians from a lookup table.
      • cos

        public static final double cos(double radians)
        Returns the cosine in radians from a lookup table.
      • acos

        public static final double acos(double x)
        Returns the arc cosine in radians from a lookup table.
      • acos_v1

        public static final double acos_v1(double x)
        Arc cos approximation
        Returns:
      • sinDeg

        public static final double sinDeg(double degrees)
        Returns the sine in radians from a lookup table.
      • cosDeg

        public static final double cosDeg(double degrees)
        Returns the cosine in radians from a lookup table.
      • atan2

        public static final double atan2(double y,
                                         double x)
        Returns atan2 in radians from a lookup table.
      • nextPowerOfTwo

        public static int nextPowerOfTwo(int value)
        Returns the next power of two. Returns the specified value if the value is already a power of two.
      • isPowerOfTwo

        public static boolean isPowerOfTwo(int value)
      • clamp

        public static int clamp(int value,
                                int min,
                                int max)
      • clamp

        public static short clamp(short value,
                                  short min,
                                  short max)
      • clamp

        public static float clamp(float value,
                                  float min,
                                  float max)
      • clamp

        public static double clamp(double value,
                                   double min,
                                   double max)
      • floor

        public static int floor(double x)
        Returns the largest integer less than or equal to the specified double. This method will only properly floor doubles from -(2^14) to (Float.MAX_VALUE - 2^14).
      • floorPositive

        public static int floorPositive(double x)
        Returns the largest integer less than or equal to the specified double. This method will only properly floor doubles that are positive. Note this method simply casts the double to int.
      • ceil

        public static int ceil(double x)
        Returns the smallest integer greater than or equal to the specified double. This method will only properly ceil doubles from -(2^14) to (Float.MAX_VALUE - 2^14).
      • ceilPositive

        public static int ceilPositive(double x)
        Returns the smallest integer greater than or equal to the specified double. This method will only properly ceil doubles that are positive.
      • round

        public static int round(double x)
        Returns the closest integer to the specified double. This method will only properly round doubles from -(2^14) to (Float.MAX_VALUE - 2^14).
      • roundPositive

        public static int roundPositive(double x)
        Returns the closest integer to the specified double. This method will only properly round doubles that are positive.
      • isZero

        public static boolean isZero(double value)
        Returns true if the value is zero (using the default tolerance as upper bound)
      • isZero

        public static boolean isZero(double value,
                                     double tolerance)
        Returns true if the value is zero.
        Parameters:
        tolerance - represent an upper bound below which the value is considered zero.
      • isEqual

        public static boolean isEqual(double a,
                                      double b)
        Returns true if a is nearly equal to b. The function uses the default doubleing error tolerance.
        Parameters:
        a - the first value.
        b - the second value.
      • isEqual

        public static boolean isEqual(double a,
                                      double b,
                                      double tolerance)
        Returns true if a is nearly equal to b.
        Parameters:
        a - the first value.
        b - the second value.
        tolerance - represent an upper bound below which the two values are considered equal.
      • sqrt

        public static double sqrt(double value)
        Fast sqrt method. Default passes it through one round of Newton's method.
        Parameters:
        value -
        Returns:
      • rint_v2

        public static double rint_v2(double x)
      • cos_core

        public static double cos_core(double x)
      • sin_core

        public static double sin_core(double x)
      • asin_core

        public static double asin_core(double x)
      • sin_v2

        public static double sin_v2(double x)
      • acos_v2

        public static double acos_v2(double x)
      • lint

        public static double lint(double x,
                                  double x0,
                                  double x1,
                                  double y0,
                                  double y1)
        Lineal interpolation.
        Parameters:
        x - The value to interpolate.
        x0 - Inferior limit to the independent value.
        x1 - Superior limit to the independent value.
        y0 - Inferior limit to the dependent value.
        y1 - Superior limit to the dependent value.
        Returns:
      • lint

        public static float lint(float x,
                                 float x0,
                                 float x1,
                                 float y0,
                                 float y1)
        Lineal interpolation.
        Parameters:
        x - The value to interpolate.
        x0 - Inferior limit to the independent value.
        x1 - Superior limit to the independent value.
        y0 - Inferior limit to the dependent value.
        y1 - Superior limit to the dependent value.
        Returns:

DMelt 3.0 © DataMelt by jWork.ORG