TIL `Math.hypot(x, y)` in JS is waaaaay slower than `Math.sqrt(x*x + y*y)`.
-
TIL `Math.hypot(x, y)` in JS is waaaaay slower than `Math.sqrt(x*x + y*y)`. Apparently it uses a more precise algorithm under the hood: something something underflows overflows numerical stability.
Time to strip them all out of my codebase. ><
@jonikorpi Huh… I often use that in various languages to save a bit out typing when dx or dy are calculated values. I assumed it was just a shortcut…
-
@jonikorpi Huh… I often use that in various languages to save a bit out typing when dx or dy are calculated values. I assumed it was just a shortcut…
@slembcke Me too. :s Hopefully the performance difference isn't as bad in other languages. Already varies quite a bit between browser engines.
-
@jonikorpi @sinbad @lisyarus i saw a thing recently claiming audiophiles couldn't tell the difference between doubles, a banana, and wet mud!