Skip to content

Commit 03e72a4

Browse files
authored
math.unsigned: fix rotate_left() for uint256, add test (#24872)
1 parent e850f6c commit 03e72a4

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎vlib/math/unsigned/uint256.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ pub fn (u Uint256) rotate_left(k int) Uint256 {
348348
return Uint256{u.hi, u.lo}
349349
}
350350

351-
return Uint256{Uint128{u.hi.lo << n | u.lo.hi >> (64 - n), u.hi.hi << n | u.hi.lo >> (64 - n)}, Uint128{}}
351+
return Uint256{Uint128{u.hi.lo << n | u.lo.hi >> (64 - n), u.hi.hi << n | u.hi.lo >> (64 - n)}, Uint128{u.lo.lo << n | u.hi.hi >> (64 - n), u.lo.hi << n | u.lo.lo >> (64 - n)}}
352352
}
353353
n -= 64
354354
if n == 0 {

‎vlib/math/unsigned/uint256_test.v‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,8 @@ fn test_lsh() {
303303
assert a.lsh(200).str() == '197653379443855803891661337357963000110230968235283518742069248'
304304
assert a.lsh(300) == unsigned.uint256_zero
305305
}
306+
307+
fn test_rotate_left() {
308+
a := unsigned.uint256_from_dec_str('25514942427378518882041616545065271187265095759155217686057363902268374351523')!
309+
assert a.rotate_left(182).str() == '88706376393829417451765793453791860419270208590599379720310994108668904859637'
310+
}

0 commit comments

Comments
 (0)