Skip to content

Commit

Permalink
Fix shl and shr (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumlamm authored Jul 28, 2023
1 parent ed8be08 commit 38eb846
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bigints.nim
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ func `shl`*(x: BigInt, y: Natural): BigInt =
assert a shl 1 == 48.initBigInt
assert a shl 2 == 96.initBigInt

if x.isZero:
return x

var carry = 0'u64
let a = y div 32
let b = uint32(y mod 32)
Expand All @@ -503,6 +506,8 @@ func `shr`*(x: BigInt, y: Natural): BigInt =

var carry = 0'u64
let a = y div 32
if a >= x.limbs.len:
return zero
let b = uint32(y mod 32)
let mask = (1'u32 shl b) - 1
result.limbs.setLen(x.limbs.len - a)
Expand Down

0 comments on commit 38eb846

Please sign in to comment.