jhplot.math
Class MathUtilsd
- java.lang.Object
-
- jhplot.math.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.
-
-
Field Summary
Fields Modifier and Type Field and Description static double
degRad
static double
degreesToRadians
multiply by this to convert from degrees to radiansstatic double
E
static double
FLOAT_ROUNDING_ERROR
static double
nanoToSec
static double
PI
static double
PI2
static double
radDeg
static double
radiansToDegrees
multiply by this to convert from radians to degrees
-
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 approximationstatic 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.
-
-
-
Field Detail
-
nanoToSec
public static final double nanoToSec
- See Also:
- Constant Field Values
-
FLOAT_ROUNDING_ERROR
public static final double FLOAT_ROUNDING_ERROR
- See Also:
- Constant Field Values
-
PI
public static final double PI
- See Also:
- Constant Field Values
-
PI2
public static final double PI2
- See Also:
- Constant Field Values
-
E
public static final double E
- See Also:
- Constant Field Values
-
radiansToDegrees
public static final double radiansToDegrees
multiply by this to convert from radians to degrees- See Also:
- Constant Field Values
-
radDeg
public static final double radDeg
- See Also:
- Constant Field Values
-
degreesToRadians
public static final double degreesToRadians
multiply by this to convert from degrees to radians- See Also:
- Constant Field Values
-
degRad
public static final double degRad
- See Also:
- Constant Field Values
-
-
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