gpt4 book ai didi

javascript - JavaScript 数学函数 (atan2) 的最后一位数字的浏览器差异是否在规范范围内?

转载 作者:行者123 更新时间:2023-12-03 00:02:55 31 4
gpt4 key购买 nike

我发现 Firefox 和 Safari 在 Math#atan2 输出的最后一位数字上存在差异。

我的代码:

Math.atan2(-0.49999999999999994, 0.8660254037844387)

Safari (12.1.1) 给出 -0.5235987755982988,但 Firefox (Mac/67.0) 给出 -0.5235987755982987

这当然是一个微小的差异。然而,似乎所有实现都应该在所有输入上产生相同的输出。例如,这样的差异可能会导致 if 语句根据浏览器遵循不同的路径。

我所看到的内容是否违反了 ECMAScript 规范的任何版本?

最佳答案

ECMAScript 2015 规范有这样的说法:

The behaviour of the functions acos, acosh, asin, asinh, atan, atanh, atan2, cbrt, cos, cosh, exp, expm1, hypot, log,log1p, log2, log10, pow, random, sin, sinh, sqrt, tan, and tanh is not precisely specified here except to require specific results for certain argument values that represent boundary cases of interest. For other argument values, these functions are intended to compute approximations to the results of familiar mathematical functions, but some latitude is allowed in the choice of approximation algorithms.The general intent is that an implementer should be able to use the same mathematical library for ECMAScript on a given hardware platform that is available to C programmers on that platform.

Although the choice of algorithms is left to the implementation, it is recommended (but not specified by this standard) that implementations use the approximation algorithms for IEEE 754-2008 arithmetic contained in fdlibm, the freely distributable mathematical library from Sun Microsystems (http://www.netlib.org/fdlibm).

5.1 规范有类似的语言。

所以我认为可以肯定地说这种行为没有违反规范。

关于javascript - JavaScript 数学函数 (atan2) 的最后一位数字的浏览器差异是否在规范范围内?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56486877/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com