Float Equal Problem

Understand limitations of floating point representations.Never check for equality with ==. Instead, check if the difference is less than an epsilon value.

public class Line{
    static double epsilon=0.000001;
    public double slope;
    public double yintersect;

    public Line(double s, double y){
            slope=s;
            yintersect=y;
    }

    public boolean intersect(Line line2){
            return Math.abs(slope-line2.slope)>epsilon||
            Math.abs(yintersect-line2.yintersect)<epsilon;
    }
}                

  

原文地址:https://www.cnblogs.com/Phoebe815/p/3889941.html