JavaScript's 32-bit integer operators.
JS converts both operands of |, &, ^, <<, >> and >>> to 32 bits
and gives a signed 32-bit result (unsigned for >>>); Math.imul
multiplies modulo 2^32. Elixir integers never overflow, so the pieces' hashes
and PRNGs go through these functions rather than Bitwise directly.
Every function accepts any integer, or a float, which is truncated first as JS's ToInt32 does.
Summary
Functions
a & b.
a | b.
a ^ b.
Math.imul(a, b), without building a 64-bit product.
One draw from mulberry32, the PRNG most pieces seed: given the state, the
next number in [0, 1) and the next state. Start from to_int32(seed).
a >> n.
a << n.
x | 0.
x >>> 0.
x >>> 0 for a value already known to be an integer or a float, without
the sign handling: the fast path for hashes, which stay unsigned.
Math.imul(a, b) >>> 0 for two unsigned 32-bit integers.
a >>> n.
Types
Functions
a & b.
a | b.
a ^ b.
Math.imul(a, b), without building a 64-bit product.
One draw from mulberry32, the PRNG most pieces seed: given the state, the
next number in [0, 1) and the next state. Start from to_int32(seed).
a = (a + 0x6d2b79f5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
a >> n.
a << n.
x | 0.
x >>> 0.
x >>> 0 for a value already known to be an integer or a float, without
the sign handling: the fast path for hashes, which stay unsigned.
Math.imul(a, b) >>> 0 for two unsigned 32-bit integers.
A hash that only ever feeds ^, >>>, + and Math.imul with its
intermediate values can work in unsigned arithmetic throughout, since all
four agree modulo 2^32 whatever the signs; this skips imul/2's
conversions and is several times faster.
a >>> n.