1 回答
TA贡献1821条经验 获得超6个赞
这种问题你想知道结果,只能去看ECMAScript 标准,因为一个取模(余数)运算的定义里,小学生都知道被除数需要是非0,对于这种情况如何处理?当然是标准说怎么处理,就怎么处理
es7标准
找到关于 % 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.
看我加粗的那句话,这就不需要我翻译了吧。。
添加回答
举报