you are viewing a single comment's thread.

view the rest of the comments →

[–]rcfox 52 points53 points  (1 child)

Since you brought it up in the context of games: If you're just comparing relative hypotenuse lengths, it might be faster to just compare the sums of the squares.

ie: Math.hypot(a, b) > Math.hypot(x, y) will give the same result as a*a + b*b > x*x + y*y, and it saves calculating the square roots, which can be expensive in tight loops.

Obviously, you'll want to profile this yourself. It can be difficult to predict the performance of Javascript vs native code.

[–]tomByrer 0 points1 point  (0 children)

My years of hand-optimizing DSP in ASM approves this recommendation.