JavaScript represents numbers as IEEE 754 doubles, which are deterministic. Nether less, I've seen arguments that some compiler optimizations can change the order of floating point operations, bringing non-determinism across different runs. So, the question is: using no other source of non-determinism (Math.random, etc.), will a Number -> Number JavaScript function always produce the same result independent of platform and engine?
some compiler optimizations can change the order of floating point operations, bringing non-determinism across different runs
The ECMAScript specification does not discuss such optimizations. In general it is however expected (like it's explicitly noted for some TypedArray algorithms) that "optimization must not introduce any observable changes in the specified behaviour of the algorithm." And evaluation order for operators is quite strictly specified in ECMAScript.
So unless proven wrong by an implementation that does such stuff (and whose standard-compliance would yet need to be determined), we can assume that the answer is Yes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With