Skip to content

Instantly share code, notes, and snippets.

@kripod
Last active February 19, 2020 16:06
Show Gist options
  • Save kripod/40594d7677d1885a9f77484e049c4fe7 to your computer and use it in GitHub Desktop.
Save kripod/40594d7677d1885a9f77484e049c4fe7 to your computer and use it in GitHub Desktop.
Optimized Math.imul() for JavaScript
function imul2(x, yHi, yLo) {
return (((x * yHi) << 16) + x * y) | 0;
}
function imul(x, y) {
return imul2(x, (y >>> 16) & 0xffff, y & 0xffff);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment