1 回答

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超6個贊
這種問題你想知道結(jié)果,只能去看ECMAScript 標(biāo)準(zhǔn),因?yàn)橐粋€取模(余數(shù))運(yùn)算的定義里,小學(xué)生都知道被除數(shù)需要是非0,對于這種情況如何處理?當(dāng)然是標(biāo)準(zhǔn)說怎么處理,就怎么處理
es7標(biāo)準(zhǔn)
找到關(guān)于 % opeartor的定義
12.7.3.3 Applying the % Operator:
If either operand is NaN, the result is NaN.
The sign of the result equals the sign of the dividend.
If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
If the dividend is finite and the divisor is an infinity, the result
equals the dividend.
If the dividend is a zero and the divisor is nonzero and finite, the result is the same as the dividend. In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n - (d × q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d. r is computed and rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode.
看我加粗的那句話,這就不需要我翻譯了吧。。
添加回答
舉報