Java examples for java.lang:Math Algorithm
Returns true if the Double value difference is minor to 1e-12.
import java.awt.geom.Point2D; import java.awt.geom.Point2D.Double; public class Main{ public static void main(String[] argv) throws Exception{ double pointA = 2.45678; double pointB = 2.45678; System.out.println(comparePoints(pointA,pointB)); }/*from w w w . ja v a 2 s. co m*/ private static final double EPS = 1e-12; /** * Returns true if the difference is minor to 1e-12. * @param pointA a point * @param pointB a point * @return true if pointA equal to pointB */ public static boolean comparePoints(Double pointA, Double pointB) { if (Math.abs(pointA.getX() - pointB.getX()) < EPS) { if (Math.abs(pointA.getY() - pointB.getY()) < EPS) { return true; } } return false; } }