Class Numbers

java.lang.Object
com.myscript.util.Numbers

public final class Numbers extends Object
Set of utility functions to compare floating point values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final float
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    hashCode(double x)
    Returns a hash code for this Double object.
    static int
    hashCode(float x)
    Returns a hash code for a Float object.
    static boolean
    isNear(double x, double y)
    Compares two values and returns `true` if they are near each other.
    static boolean
    isNear(double x, double y, double absolute_tolerance, double relative_tolerance)
    Compares two values and returns `true` if they are near each other.
    static boolean
    isNear(float x, float y)
    Compares two values and returns `true` if they are near each other.
    static boolean
    isNear(float x, float y, float absolute_tolerance, float relative_tolerance)
    Compares two values and returns `true` if they are near each other.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • isNear

      public static boolean isNear(float x, float y, float absolute_tolerance, float relative_tolerance)
      Compares two values and returns `true` if they are near each other.
      Parameters:
      x - the first value to compare.
      y - the second value to compare.
      absolute_tolerance - the absolute tolerance for the comparison.
      relative_tolerance - the relative tolerance for the comparison.
      Returns:
      `true` if `x` and `y` are near, false otherwise.
    • isNear

      public static boolean isNear(float x, float y)
      Compares two values and returns `true` if they are near each other. Tolerance is the the difference between 1.0 and the next representable value of the given floating-point type.
      Parameters:
      x - the first value to compare.
      y - the second value to compare.
      Returns:
      `true` if `x` and `y` are near, false otherwise.
    • isNear

      public static boolean isNear(double x, double y, double absolute_tolerance, double relative_tolerance)
      Compares two values and returns `true` if they are near each other.
      Parameters:
      x - the first value to compare.
      y - the second value to compare.
      absolute_tolerance - the absolute tolerance for the comparison.
      relative_tolerance - the relative tolerance for the comparison.
      Returns:
      `true` if `x` and `y` are near, false otherwise.
    • isNear

      public static boolean isNear(double x, double y)
      Compares two values and returns `true` if they are near each other. Tolerance is the the difference between 1.0 and the next representable value of the given double-point type.
      Parameters:
      x - the first value to compare.
      y - the second value to compare.
      Returns:
      `true` if `x` and `y` are near, false otherwise.
    • hashCode

      public static int hashCode(float x)
      Returns a hash code for a Float object.
      Parameters:
      x - the float to hash.
      Returns:
      a hash code value for this object
    • hashCode

      public static int hashCode(double x)
      Returns a hash code for this Double object.
      Parameters:
      x - the Double to hash.
      Returns:
      a hash code value for this object.