toji / gl-matrix

Javascript Matrix and Vector library for High Performance WebGL apps
glmatrix.net
MIT License
5.37k stars 721 forks source link

Replace Math.hypot with Math.sqrt #449

Closed platypii closed 2 years ago

platypii commented 2 years ago

Fixes #446

This PR replaces all instances of Math.hypot with Math.sqrt. It also removes the polyfill for hypot on really old browsers.

The reason is that sqrt is MUCH faster than hypot on all modern javascript engines. See #446 for some benchmarks.

While hypot is nicer to write, and is technically more accurate especially for very large and very small numbers, I think that the performance gains from switching to sqrt are worth it. Especially for a library with the goal:

glMatrix is designed to perform vector and matrix operations stupidly fast!

Suggestions and feedback appreciated.

mreinstein commented 2 years ago

very elegant solution @platypii