计算几何误差修正cmp

//计算几何误差修正
Math.EPS=0.00000001;
//判断x的符号
Math.cmp=function(x) {
    if(Math.abs(x)<Math.EPS)return 0;
    if(x>0){
        return 1;
    }else{
        return -1;
    }
}

console.log(Math.cmp(0.1+0.2-0.3))
console.log(Math.cmp(0.0001))

 

posted @ 2019-03-14 11:03  无工时代  阅读(234)  评论(0)    收藏  举报