Package com.reportmill.base
Class RMMath
- java.lang.Object
-
- com.reportmill.base.RMMath
-
public class RMMath extends java.lang.ObjectUtility methods for common math operations.
-
-
Constructor Summary
Constructors Constructor Description RMMath()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Numberadd(java.lang.Number n1, java.lang.Number n2)Returns the sum of the two given Numbers.static booleanbetween(float a, float x, float y)Returns whether a real number is between two other numbers.static floatclamp(double d)Returns the given double clamped to 1/1000th precision.static floatclamp(float f)Returns the given float clamped to 1/1000th precision.static floatclamp(float f, float min, float max)Returns the given double clamped between the two values.static intclamp(int i, int min, int max)Returns the given in clamped between the two values.static doubleclamp_doubleback(double a, double x, double y)Returns the given double clamped between the two values.static doubleclamp_wrap(double a, double x, double y)Returns the given double clamped between the two values (wraps around if out of range).static intclamp_wrap(int a, int x, int y)Returns the given double clamped between the two values (wraps around if out of range).static doublecos(double anAngle)Returns the cos of the given angle in degrees.static floatcos(float anAngle)Returns the cos of the given angle in degrees.static java.lang.Numberdivide(java.lang.Number n1, java.lang.Number n2)Returns the result of dividing n1 by n2.static booleanequals(double a, double b)Returns whether two real numbers are equal within a small tolerance.static booleanequalsZero(float a)Returns whether a real number is practically zero.static java.util.ListgetIntervalsFor(float maxValue)Returns well-chosen intervals from zero to a given a value.static java.util.ListgetIntervalsFor(float minValue, float maxValue)Return well-chosen intervals given a min/max value.static booleangt(float a, float b)Returns whether a real number is practically greater than another.static booleangte(float a, float b)Returns whether a real number is practically greater than or equal another.static booleanlt(float a, float b)Returns whether a real number is practically less than another.static booleanlte(float a, float b)Returns whether a real number is practically less than or equal another.static doublemod(double x, double y)Returns the given number modulo the second number (mod for floats).static java.lang.Numbermultiply(java.lang.Number n1, java.lang.Number n2)Returns the product of the two given Numbers.static java.lang.Numbernegate(java.lang.Number aNumber)Returns the negative of the given Number.static intrandomInt()Returns a random int.static java.lang.IntegerrandomInteger()Returns a random Integer.static doubleround(double x, double y)Returns the given number rounded to the second number (rounding to arbitrary double values).static floatround(float x, float y)Returns the given number rounded to the second number (rounding to arbitrary floating values).static intsign(float f)Returns the sign of a given number (as -1 or 1).static doublesin(double anAngle)Returns the sign of the given angle in degrees.static floatsin(float anAngle)Returns the sign of the given angle in degrees.static java.lang.Numbersubtract(java.lang.Number n1, java.lang.Number n2)Returns the difference of the two given Numbers.static floattrunc(float x, float 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(float a)
Returns whether a real number is practically zero.
-
gt
public static boolean gt(float a, float b)Returns whether a real number is practically greater than another.
-
gte
public static boolean gte(float a, float b)Returns whether a real number is practically greater than or equal another.
-
lt
public static boolean lt(float a, float b)Returns whether a real number is practically less than another.
-
lte
public static boolean lte(float a, float b)Returns whether a real number is practically less than or equal another.
-
between
public static boolean between(float a, float x, float y)Returns whether a real number is between two other numbers.
-
sign
public static int sign(float f)
Returns the sign of a given number (as -1 or 1).
-
sin
public static float sin(float anAngle)
Returns the sign of the given angle in degrees.
-
cos
public static float cos(float anAngle)
Returns the cos of the given angle in degrees.
-
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.
-
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).
-
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.
-
negate
public static java.lang.Number negate(java.lang.Number aNumber)
Returns the negative of the given Number.
-
trunc
public static float trunc(float x, float y)Truncate x down to the nearest y.
-
clamp
public static float clamp(float f)
Returns the given float clamped to 1/1000th precision.
-
clamp
public static float clamp(double d)
Returns the given double 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(float f, float min, float 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.
-
randomInt
public static int randomInt()
Returns a random int.
-
randomInteger
public static java.lang.Integer randomInteger()
Returns a random Integer.
-
getIntervalsFor
public static java.util.List getIntervalsFor(float minValue, float maxValue)Return well-chosen intervals given a min/max value. For instance, (1,4) would return (1,2,3,4,5), while (17,242) would return (50,100,150,200,250). Useful methods for graphing.
-
getIntervalsFor
public static java.util.List getIntervalsFor(float maxValue)
Returns well-chosen intervals from zero to a given a value. Finds the first multiple of {5,10 or 25}*10^n that equals or exceeds max value, then divides by 5. This method could probably be done a lot simpler.
-
-