9**66 != n**66 with n=9 in Node 11.6.0

Viewed 171

While looking for some black magic used in this answer to a Code Golf challenge, I've noticed the following behavior in Node 11.6.0:

// 1) exact result with BigInts
console.log(9n ** 66n);         // 95500495(...)3841n
console.log(9n ** 66n % 79n);   // 21n

// 2) approximation with a Number literal
console.log(9 ** 66);           // 9.550049507968253e+62
console.log(9 ** 66 % 79);      // 71

// 3) approximation with a variable
let n = 9;
console.log(n ** 66);           // 9.550049507968251e+62
console.log(n ** 66 % 79);      // 69

Essentially, n ** 66 with n = 9 doesn't lead to the same result as 9 ** 66, which is something I've never experienced before, although I've done a lot of similar weird things on Code Golf.

You can run the above code on the Try it online! service, which has Node v11.6.0 installed at the time of posting.

My current local Node version is 12.13.1, which consistently gives 71 in both cases.

Is this a known issue of Node 11.6.0? Do other Node versions and/or other JS engines behave the same way?


Addendum

Below is a simpler example with 9 ** 17:

console.log(9n ** 17n); // 16677181699666569n
console.log(9 ** 17);   // 16677181699666570
let n = 9;
console.log(n ** 17);   // 16677181699666568
0 Answers
Related