```javascript function premiumBps(tokenPriceCents, referencePriceCents) { if (typeof tokenPriceCents !== 'number' || !Number.isInteger(tokenPriceCents) || typeof referencePriceCents !== 'number' || !Number.isInteger(referencePriceCents)) { throw new RangeError('Both prices must be integer numbers.'); } if (tokenPriceCents < 0 || tokenPriceCents > 1000000000) { throw new RangeError('tokenPriceCents must be between 0 and 1,000,000,000 inclusive.'); } if (referencePriceCents < 1 || referencePriceCents > 1000000000) { throw new RangeError('referencePriceCents must be between 1 and 1,000,000,000 inclusive.'); } // Compute sign and magnitude of the premium exactly using integer arithmetic, // then round |numerator * 10000 / reference| to nearest, half away from zero. const numerator = tokenPriceCents - referencePriceCents; // safe: |diff| <= 1e9 if (numerator === 0) { return 0; } const sign = numerator < 0 ? -1 : 1; const absNumerator = sign < 0 ? -numerator : numerator; // <= 1e9 // absNumerator <= 1e9, so absNumerator * 10000 <= 1e13, within 2^53. const scaled = absNumerator * 10000; const reference = referencePriceCents; let rounded = Math.floor(scaled / reference); const remainder = scaled - rounded * reference; // exact, both terms safe // Round half away from zero: bump when remainder >= reference / 2. // Compare 2 * remainder >= reference without division. if (2 * remainder >= reference) { rounded += 1; } // rounded <= 1e13, so applying sign stays safe. const result = sign < 0 ? -rounded : rounded; // Normalize negative zero to positive zero. return result === 0 ? 0 : result; } ``` **Validation:** Each input is checked with `typeof` and `Number.isInteger`, so strings, `null`, `undefined`, booleans, `NaN`, `Infinity`, and fractional values are all rejected without coercion. Integer checks also exclude non-finite numbers. Ranges are then enforced (`0..1e9` for the token price, `1..1e9` for the reference). Every failure throws a `RangeError`. **Rounding:** The exact quotient `|token − reference| × 10000 / reference` is computed with integer division. The remainder is compared against half the reference (`2 * remainder >= reference`) to decide a round-up. This yields round-half-away-from-zero on the magnitude, and the original sign is reapplied. Since `|difference| ≤ 1e9`, `|difference| × 10000 ≤ 1e13`, which is well under `2^53`, so all intermediate values are exact. A zero result is returned as positive `0`.