第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

10%0 結(jié)果為NaN?

10%0 結(jié)果為NaN?

胡說叔叔 2018-12-20 18:14:49
任何數(shù)取余0,為什么結(jié)果為NaN;10 % 0;> NaN感謝各位的解答,我覺得還是有些欠妥當(dāng)。都知道 任何數(shù) /0 得到的是 Infinity 無窮大的,雖然 %0的計算過程中也涉及除法運(yùn)算,但是它的結(jié)果卻是NaN 而不是 Infinity;本質(zhì)上是有區(qū)別的,javascript指南中提到: 算術(shù)運(yùn)算中使用了不恰當(dāng)?shù)牡牟僮鲾?shù),導(dǎo)致【運(yùn)算失敗】,該運(yùn)算就會返回 NaN 。然而 任何數(shù) /0 返回的是 Infinity,這代表的是運(yùn)算是 【成功】 的。所以我覺得最終返回的 NaN 還是有某個地方的運(yùn)算是有問題的。比如我們都知道 'a'/10 ,結(jié)果是NaN,因?yàn)橐粋€字符,一個是數(shù)字,報錯是理所當(dāng)然的。但是 10%0 為何報錯為NaN?
查看完整描述

1 回答

?
達(dá)令說

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.

看我加粗的那句話,這就不需要我翻譯了吧。。


查看完整回答
反對 回復(fù) 2019-01-24
  • 1 回答
  • 0 關(guān)注
  • 694 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號