Class RMMath

java.lang.Object
com.reportmill.base.RMMath

public class RMMath extends Object
Utility methods for common math operations.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Number
    add(Number n1, Number n2)
    Returns the sum of the two given Numbers.
    static boolean
    between(float a, float x, float y)
    Returns whether a real number is between two other numbers.
    static float
    clamp(double d)
    Returns the given double clamped to 1/1000th precision.
    static float
    clamp(float f)
    Returns the given float clamped to 1/1000th precision.
    static float
    clamp(float f, float min, float 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 float
    cos(float anAngle)
    Returns the cos of the given angle in degrees.
    static Number
    divide(Number n1, 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(float a)
    Returns whether a real number is practically zero.
    static List
    getIntervalsFor(float maxValue)
    Returns well-chosen intervals from zero to a given a value.
    static List
    getIntervalsFor(float minValue, float maxValue)
    Return well-chosen intervals given a min/max value.
    static boolean
    gt(float a, float b)
    Returns whether a real number is practically greater than another.
    static boolean
    gte(float a, float b)
    Returns whether a real number is practically greater than or equal another.
    static boolean
    lt(float a, float b)
    Returns whether a real number is practically less than another.
    static boolean
    lte(float a, float 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 Number
    Returns the product of the two given Numbers.
    static Number
    negate(Number aNumber)
    Returns the negative of the given Number.
    static int
    Returns a random int.
    static Integer
    Returns a random Integer.
    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(float 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 float
    sin(float anAngle)
    Returns the sign of the given angle in degrees.
    static Number
    Returns the difference of the two given Numbers.
    static float
    trunc(float x, float y)
    Truncate x down to the nearest y.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static Number add(Number n1, Number n2)
      Returns the sum of the two given Numbers.
    • subtract

      public static Number subtract(Number n1, Number n2)
      Returns the difference of the two given Numbers.
    • multiply

      public static Number multiply(Number n1, Number n2)
      Returns the product of the two given Numbers.
    • divide

      public static Number divide(Number n1, Number n2)
      Returns the result of dividing n1 by n2.
    • negate

      public static Number negate(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 Integer randomInteger()
      Returns a random Integer.
    • getIntervalsFor

      public static 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 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.