Class Precision


  • public class Precision
    extends Object
    Compare doubles with a certain precision
    Author:
    markr
    • Constructor Summary

      Constructors 
      Constructor Description
      Precision()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean equal​(double d1, double d2)
      Compare using a Precision.EPSILON_6
      static boolean equal​(double d1, double d2, double epsilon)
      Compare using a custom precision epsilon
      static boolean greater​(double d1, double d2)
      isGreater with Precision.EPSILON_6
      static boolean greater​(double d1, double d2, double epsilon)
      isGreaterEqual with epsilon
      static boolean greaterEqual​(double d1, double d2)
      isGreaterEqual with Precision.EPSILON_6
      static boolean greaterEqual​(double d1, double d2, double epsilon)
      isGreaterEqual with epsilon
      static boolean negative​(double d1)
      Verify if negative with Precision.EPSILON_6
      static boolean nonZero​(double d1)
      Verify if non-zero with Precision.EPSILON_6
      static boolean notEqual​(double d1, double d2)
      static boolean notEqual​(double d1, double d2, double epsilon)
      static boolean positive​(double d1)
      Verify if positive with Precision.EPSILON_6
      static boolean positive​(double d1, double epsilon)
      Verify if positive with Precision.EPSILON_6
      static boolean smaller​(double d1, double d2)
      isSmaller with Precision.EPSILON_6
      static boolean smaller​(double d1, double d2, double epsilon)
      isSmaller with epsilon
      static boolean smallerEqual​(double d1, double d2)
      isSmallerEqual with Precision.EPSILON_6
      static boolean smallerEqual​(double d1, double d2, double epsilon)
      isSmallerEqual with epsilon
    • Constructor Detail

      • Precision

        public Precision()
    • Method Detail

      • equal

        public static boolean equal​(double d1,
                                    double d2,
                                    double epsilon)
        Compare using a custom precision epsilon
        Parameters:
        d1 - double1
        d2 - double2
        epsilon - epsilon value
        Returns:
        true when equal within epsilon, false otherwise
      • equal

        public static boolean equal​(double d1,
                                    double d2)
        Compare using a Precision.EPSILON_6
        Parameters:
        d1 - double1
        d2 - double2
        Returns:
        true when equal within epsilon, false otherwise
      • smallerEqual

        public static boolean smallerEqual​(double d1,
                                           double d2,
                                           double epsilon)
        isSmallerEqual with epsilon
        Parameters:
        d1 - double1
        d2 - double2
        epsilon - epsilon value
        Returns:
        true when d1 <= (d2 + epsilon)
      • smaller

        public static boolean smaller​(double d1,
                                      double d2)
        isSmaller with Precision.EPSILON_6
        Parameters:
        d1 - double1
        d2 - double2
        Returns:
        true when (d1 + epsilon) < d2
      • smaller

        public static boolean smaller​(double d1,
                                      double d2,
                                      double epsilon)
        isSmaller with epsilon
        Parameters:
        d1 - double1
        d2 - double2
        epsilon - epsilon value
        Returns:
        true when (d1 +epsilon) < d2
      • smallerEqual

        public static boolean smallerEqual​(double d1,
                                           double d2)
        isSmallerEqual with Precision.EPSILON_6
        Parameters:
        d1 - double1
        d2 - double2
        Returns:
        true when d1 <= (d2 + epsilon)
      • greaterEqual

        public static boolean greaterEqual​(double d1,
                                           double d2,
                                           double epsilon)
        isGreaterEqual with epsilon
        Parameters:
        d1 - double1
        d2 - double2
        epsilon - epsilon value
        Returns:
        true when d1 >= (d2 - epsilon)
      • greaterEqual

        public static boolean greaterEqual​(double d1,
                                           double d2)
        isGreaterEqual with Precision.EPSILON_6
        Parameters:
        d1 - double1
        d2 - double2
        Returns:
        true when d1 >= (d2- epsilon)
      • greater

        public static boolean greater​(double d1,
                                      double d2,
                                      double epsilon)
        isGreaterEqual with epsilon
        Parameters:
        d1 - double1
        d2 - double2
        epsilon - epsilon value
        Returns:
        true when (d1 - epsilon) > d2
      • greater

        public static boolean greater​(double d1,
                                      double d2)
        isGreater with Precision.EPSILON_6
        Parameters:
        d1 - double1
        d2 - double2
        Returns:
        true when (d1 - epsilon) > d2
      • positive

        public static boolean positive​(double d1)
        Verify if positive with Precision.EPSILON_6
        Parameters:
        d1 - double 1
        Returns:
        true when d1 > EPSILON_6
      • positive

        public static boolean positive​(double d1,
                                       double epsilon)
        Verify if positive with Precision.EPSILON_6
        Parameters:
        d1 - double 1
        epsilon - to consider
        Returns:
        true when d1 > epsilon
      • negative

        public static boolean negative​(double d1)
        Verify if negative with Precision.EPSILON_6
        Parameters:
        d1 - double 1
        Returns:
        true when d1 < -EPSILON_6
      • nonZero

        public static boolean nonZero​(double d1)
        Verify if non-zero with Precision.EPSILON_6
        Parameters:
        d1 - double 1
        Returns:
        true when d1 < -EPSILON_6 or d1 > EPSILON_6
      • notEqual

        public static boolean notEqual​(double d1,
                                       double d2)
        Parameters:
        d1 - to use
        d2 - to use
        Returns:
        true when not equal, false otherwise
      • notEqual

        public static boolean notEqual​(double d1,
                                       double d2,
                                       double epsilon)
        Parameters:
        d1 - to use
        d2 - to use
        epsilon - to use
        Returns:
        true when not equal, false otherwise