201702112331_《js缺陷-数值比较补救》
const EPSILON = Math.pow(2, -53); //1.1102230246251565e-16
function epsEqu(x,y) {
return Math.abs(x - y) < EPSILON;
}
epsEqu(0.1+0.2, 0.3) //true
前端-语言
const EPSILON = Math.pow(2, -53); //1.1102230246251565e-16
function epsEqu(x,y) {
return Math.abs(x - y) < EPSILON;
}
epsEqu(0.1+0.2, 0.3) //true