Package com.reportmill.base
Class RMMath
java.lang.Object
com.reportmill.base.RMMath
Utility methods for common math operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NumberReturns 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 NumberReturns 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 ListgetIntervalsFor(float maxValue) Returns well-chosen intervals from zero to a given a value.static 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 NumberReturns the product of the two given Numbers.static NumberReturns the negative of the given Number.static intReturns a random int.static IntegerReturns 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 NumberReturns the difference of the two given Numbers.static floattrunc(float x, float y) Truncate x down to the nearest y.
-
Constructor Details
-
RMMath
public RMMath()
-
-
Method Details
-
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
Returns the sum of the two given Numbers. -
subtract
Returns the difference of the two given Numbers. -
multiply
Returns the product of the two given Numbers. -
divide
Returns the result of dividing n1 by n2. -
negate
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
Returns a random Integer. -
getIntervalsFor
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
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.
-