UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

15 lines (13 loc) 433 B
import { assert } from "../assert.js"; /** * Branchless fast integer Absolute value function. * Same as Math.abs(x) but for integer values only. * Only valid for integers up to and including 32 bit. * @param {number} x * @return {number} */ export function iabs(x) { // adapted from https://graphics.stanford.edu/~seander/bithacks.html assert.isInteger(x, 'x'); return (x ^ (x >> 31)) - (x >> 31); }