Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shl and shr #134

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
konsumlamm marked this conversation as resolved.
Show resolved Hide resolved
let b = uint32(y mod 32)
let mask = (1'u32 shl b) - 1
result.limbs.setLen(x.limbs.len - a)
Expand Down