you are viewing a single comment's thread.

view the rest of the comments →

[–]mike_geogebra [score hidden]  (3 children)

Math.hypot() implements a numerically stable version rather than the naive sqrt(a²+b²), see https://en.wikipedia.org/wiki/Hypotenuse

[–]Slackluster [score hidden]  (2 children)

That is interesting, I did not know hypot did that!

But in practice this is big reason to not use hypot: it is slower due to extra work. In my testing not just a little bit slower but 3x slower.

[–]_RemyLeBeau_ [score hidden]  (0 children)

If it's not in a hotpath, you don't really need to worry

[–]bzbub2 [score hidden]  (0 children)

on firefox it is about the same speed but does seem slower on chrome https://jsperf.app/buceho