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

标签 javascript language-lawyer specifications atan2

我发现 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/

相关文章:

javascript - 我应该使用 $q 中的私有(private)属性 $$state 来满足我的需求吗?

javascript - Mongoose:如何使用回调中的变量更新文档?

c++ - cin 在读取错误类型时会覆盖我的初始化值吗?

html - block 元素内的 block 元素和内联元素

javascript - 如何在 VueJS 2.0 中进行路由

javascript - 可视化选择 HTML 元素

c++ - "typedef"在类型和别名标准符合之间吗?

c++ - 使用临时存储区 : is it allowed? 复制可简单复制的类型

html - 细节元素似乎忽略了 display flex 或 grid?

javascript - blink() 方法真的被弃用了吗?