UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

21 lines (16 loc) 566 B
import { UINT32_MAX } from "../../binary/UINT32_MAX.js"; /** * * @param {number} v * @returns {number} */ export function computeHashFloat(v) { // we break the number up into fractional and whole parts const whole = v >> 0; const fraction = v - whole; // fractional part is scaled up into uint32 range, // this inexact method, as it will produce 0 hash for values below a certain threshold, but it's fast const fractionHash = fraction * UINT32_MAX; // take XOR of both parts return fractionHash ^ whole; }