//计算几何误差修正 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))
//计算几何误差修正 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))