Are browser differences in the last digit of a JavaScript Math function (atan2) within spec?

The ECMAScript 2015 spec has this to say:

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).

The 5.1 spec has similar language.

So I think it's safe to say this behavior doesn't violate the spec.


Floating point differences like that will happen on different CPUs/FPUs and different math libraries across any language or platform. If you depend on that level of precision being exactly right, you'd be in trouble. You should always treat floating point values as "fuzzy".

ECMA spec does not specify the precision:

The Math.atan2() function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y), for Math.atan2(y,x).