码迷,mamicode.com
首页 > 其他好文 > 详细

Float Equal Problem

时间:2014-08-04 14:13:17      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:blog   java   io   for   div   line   log   res   

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;
    }
}                

  

Float Equal Problem,布布扣,bubuko.com

Float Equal Problem

标签:blog   java   io   for   div   line   log   res   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!