From 78b8a376f2a314c377b68437bc88c5ae5429ff41 Mon Sep 17 00:00:00 2001 From: Alex Kulcsar <38046796+alex-kulcsar@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:32:23 -0400 Subject: [PATCH] Shift must be an integer. --- bigint.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bigint.ts b/bigint.ts index 51ac162..4a72a34 100644 --- a/bigint.ts +++ b/bigint.ts @@ -1082,6 +1082,7 @@ namespace BigNum { export function leftShift(x: BigInt, shift: number): BigInt { if (shift === 0 || x.length === 0) return x if (shift < 0) return rightShift(x, Math.abs(shift)) + if (Math.round(shift) != shift) throw 'leftShift: shift must be an integer.' if (shift > kMaxLengthBits) throw 'leftShift: shift is too large.' const digitShift: number = (shift / 30) | 0 const bitsShift: number = shift % 30 @@ -1207,6 +1208,8 @@ namespace BigNum { */ export function rightShift(x: BigInt, shift: number): BigInt { if (x.length === 0 || shift === 0) return x + if (Math.round(shift) != shift) throw 'rightShift: shift must be an integer.' + if (shift > kMaxLengthBits) throw 'rightShift: shift is too large.' if (shift < 0) return leftShift(x, Math.abs(shift)) const length = x.length const sign = x.sign