Package com.inductiveautomation.rm.base
Class RMMath
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMMath
-
public class RMMath extends java.lang.Object
Utility methods for common math operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RMMath.RMFunc
A class used to specify an arbitrary mathematical function.
-
Constructor Summary
Constructors Constructor Description RMMath()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Number
add(java.lang.Number n1, java.lang.Number n2)
Returns the sum of the two given Numbers.static boolean
between(double a, double x, double y)
Returns whether a real number is between two other numbers.static double
ceil(double x, double y)
Truncate x up to the nearest y.static double
clamp(double f)
Returns the given float clamped to 1/1000th precision.static float
clamp(double f, double min, double max)
Returns the given double clamped between the two values.static int
clamp(int i, int min, int max)
Returns the given in clamped between the two values.static double
clamp_doubleback(double a, double x, double y)
Returns the given double clamped between the two values.static double
clamp_wrap(double a, double x, double y)
Returns the given double clamped between the two values (wraps around if out of range).static int
clamp_wrap(int a, int x, int y)
Returns the given double clamped between the two values (wraps around if out of range).static double
cos(double anAngle)
Returns the cos of the given angle in degrees.static java.lang.Number
divide(java.lang.Number n1, java.lang.Number n2)
Returns the result of dividing n1 by n2.static boolean
equals(double a, double b)
Returns whether two real numbers are equal within a small tolerance.static boolean
equalsZero(double a)
Returns whether a real number is practically zero.static double
floor(double x, double y)
Truncate x down to the nearest y.static boolean
gt(double a, double b)
Returns whether a real number is practically greater than another.static boolean
gte(double a, double b)
Returns whether a real number is practically greater than or equal another.static boolean
lt(double a, double b)
Returns whether a real number is practically less than another.static boolean
lte(double a, double b)
Returns whether a real number is practically less than or equal another.static double
mod(double x, double y)
Returns the given number modulo the second number (mod for floats).static java.lang.Number
multiply(java.lang.Number n1, java.lang.Number n2)
Returns the product of the two given Numbers.static java.lang.Number
negate(java.lang.Number aNumber)
Returns the negative of the given Number.static float
randomFloat(float aVal)
Returns a random float up to given value.static int
randomInt()
Returns a random int.static double
round(double x, double y)
Returns the given number rounded to the second number (rounding to arbitrary double values).static float
round(float x, float y)
Returns the given number rounded to the second number (rounding to arbitrary floating values).static int
sign(double f)
Returns the sign of a given number (as -1 or 1).static double
sin(double anAngle)
Returns the sign of the given angle in degrees.static java.lang.Number
subtract(java.lang.Number n1, java.lang.Number n2)
Returns the difference of the two given Numbers.static double
trunc(double x, double y)
Truncate x down to the nearest y.
-
-
-
Method Detail
-
equals
public static boolean equals(double a, double b)
Returns whether two real numbers are equal within a small tolerance.
-
equalsZero
public static boolean equalsZero(double a)
Returns whether a real number is practically zero.
-
gt
public static boolean gt(double a, double b)
Returns whether a real number is practically greater than another.
-
gte
public static boolean gte(double a, double b)
Returns whether a real number is practically greater than or equal another.
-
lt
public static boolean lt(double a, double b)
Returns whether a real number is practically less than another.
-
lte
public static boolean lte(double a, double b)
Returns whether a real number is practically less than or equal another.
-
between
public static boolean between(double a, double x, double y)
Returns whether a real number is between two other numbers.
-
sign
public static int sign(double f)
Returns the sign of a given number (as -1 or 1).
-
mod
public static double mod(double x, double y)
Returns the given number modulo the second number (mod for floats).
-
round
public static float round(float x, float y)
Returns the given number rounded to the second number (rounding to arbitrary floating values).
-
round
public static double round(double x, double y)
Returns the given number rounded to the second number (rounding to arbitrary double values).
-
trunc
public static double trunc(double x, double y)
Truncate x down to the nearest y.
-
floor
public static double floor(double x, double y)
Truncate x down to the nearest y.
-
ceil
public static double ceil(double x, double y)
Truncate x up to the nearest y.
-
clamp
public static double clamp(double f)
Returns the given float clamped to 1/1000th precision.
-
clamp
public static int clamp(int i, int min, int max)
Returns the given in clamped between the two values.
-
clamp
public static float clamp(double f, double min, double max)
Returns the given double clamped between the two values.
-
clamp_wrap
public static int clamp_wrap(int a, int x, int y)
Returns the given double clamped between the two values (wraps around if out of range).
-
clamp_wrap
public static double clamp_wrap(double a, double x, double y)
Returns the given double clamped between the two values (wraps around if out of range).
-
clamp_doubleback
public static double clamp_doubleback(double a, double x, double y)
Returns the given double clamped between the two values.
-
negate
public static java.lang.Number negate(java.lang.Number aNumber)
Returns the negative of the given Number.
-
add
public static java.lang.Number add(java.lang.Number n1, java.lang.Number n2)
Returns the sum of the two given Numbers.
-
subtract
public static java.lang.Number subtract(java.lang.Number n1, java.lang.Number n2)
Returns the difference of the two given Numbers.
-
multiply
public static java.lang.Number multiply(java.lang.Number n1, java.lang.Number n2)
Returns the product of the two given Numbers.
-
divide
public static java.lang.Number divide(java.lang.Number n1, java.lang.Number n2)
Returns the result of dividing n1 by n2.
-
sin
public static double sin(double anAngle)
Returns the sign of the given angle in degrees.
-
cos
public static double cos(double anAngle)
Returns the cos of the given angle in degrees.
-
randomInt
public static int randomInt()
Returns a random int.
-
randomFloat
public static float randomFloat(float aVal)
Returns a random float up to given value.
-
-