Inconsistent Results Across Browsers

Something’s not working the way it seems like it should.

When I enter ((6^21) * (6^-21) - 1) * 10^16 in both Firefox and Chrome.

I saw on Firefox the result given was 0 (correct), while on Chrome the result is −1.11022302463

But I expected either both results to be 0, or both to be −1.11022302463

Here’s the link to the page, dashboard, or activity: bug report

And here are some screenshots or a video:

Firefox
firefox_SNDqWn8FYX

Chrome
chrome_M3tj3THziI

Did some more testing:

On Firefox, Safari, and the iOS App, the expression returns 0.
On Chrome, Microsoft Edge, and the Android App, the expression returns about -1.11

I tested the browsers desktop apps and mobile apps, but for all 4 browsers the desktop and mobile results were the same.

The largest integer that can safely be represented in JavaScript is 2^53 - 1 (because that’s the largest safe integer in 64-bit floating-point). Anything larger than that is not guaranteed to be stored precisely. So trying to compare or do arithmetic on numbers larger than that can lead to errors.

3^35 is larger than the largest safe integer. Its actual value is 50031545098999707, but if you evaluate Math.pow(3, 35) in your browser console, it will output 50031545098999704.

Numbers larger than the max safe integer are weird. For instance, if n is one such value, n and n+1 will compare equal.

Exponentiation is also an “implementation-approximated” operation in JavaScript, meaning that different browsers implement it differently. So it is not surprising that Firefox and Chrome give different answers in this case.