IEEE754 浮點數(shù)運算標準
是20世紀80年代以來最廣泛使用的浮點數(shù)運算標準,為許多CPU與浮點運算器所采用。這個標準定義了表示浮點數(shù)的格式(包括負零-0)與反常值(denormal number)),一些特殊數(shù)值(無窮(Inf)與非數(shù)值(NaN)),以及這些數(shù)值的“浮點數(shù)運算符”;它也指明了四種數(shù)值舍入規(guī)則和五種例外狀況(包括例外發(fā)生的時機與處理方式)。
該標準的全稱為IEEE二進制浮點數(shù)算術(shù)標準(ANSI/IEEE Std 754-1985),又稱IEC 60559:1989,
"Object.is()" VS "==="
這個標準中要求NaN不等于自身
Object.is的代碼實現(xiàn)
Object.defineProperty(Object, 'is', {
value: function(x, y) {
if (x === y) {
// 0 === -0, but they are not identical
return x !== 0 || 1 / x === 1 / y;
}
// NaN !== NaN, but they are identical.
// NaNs are the only non-reflexive value, i.e., if x !== x,
// then x is a NaN.
// isNaN is broken: it converts its argument to number, so
// isNaN("foo") => true
return x !== x && y !== y;
},
configurable: true,
enumerable: false,
writable: true
});
經(jīng)驗收集
比如要判斷x是否為NaN,兩種方式
① typeof x ==="number"&&isNaN(x)===true;//是number類型,且isNaN為true。
② x !== x;//true則為NaN,NaN是js中唯一個一個不等于自身的值