I guess that Perl 5’s superior results in the squareroot test simply stem from its rounding…
Helmut Fuchs
32

Good point. Yes, I guess the result of sqrt(2) * sqrt(2) is a “trick” on Perl 5’s part. I don’t know anything about the underpinnings of Perl 5, but I’ve assumed that Perl 5 doesn’t even try to calculate the square when it stumbles over nonsense calculations like these (the same goes for Perl 6 and Julia).

In this context it doesn’t matter whether it’s a trick or not. The embedded video shows that what Matt Parker’s really testing is not precision in the strict sense, but whether the calculator software’s is smart enough to understand and compensate for trick questions like these. In that sense and in this context, Perl 5 doesn’t have to do magic — just be smart enough to understand that we try to trick it not only when calculating square roots but even when doing cube roots (and more):

$ perl -E 'say ((9 ** (1/3)) ** 3)'
9
$ perl -E 'say ((9 ** (1/4)) ** 4)'
9

Perl 6 and Julia figured this out as well.

By the way, I put Perl 5 to the test and tried your suggested calculation, and sure — it predictably ends up with…

$ perl -E 'say ((sqrt(2) * sqrt(2)) - 2)'
4.44089209850063e-16

…which, incidentally, is the exact same result as Perl 6 and Julia 1.0. So one isn’t “smarter” than the other when it comes to this.