math.unsigned: fix rotate_left() for uint256, add test (#24872)

This commit is contained in:
Mike 2025-07-10 08:45:34 +03:00 committed by GitHub
parent e850f6c678
commit 03e72a4856
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -348,7 +348,7 @@ pub fn (u Uint256) rotate_left(k int) Uint256 {
return Uint256{u.hi, u.lo}
}
return Uint256{Uint128{u.hi.lo << n | u.lo.hi >> (64 - n), u.hi.hi << n | u.hi.lo >> (64 - n)}, Uint128{}}
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)}}
}
n -= 64
if n == 0 {

View File

@ -303,3 +303,8 @@ fn test_lsh() {
assert a.lsh(200).str() == '197653379443855803891661337357963000110230968235283518742069248'
assert a.lsh(300) == unsigned.uint256_zero
}
fn test_rotate_left() {
a := unsigned.uint256_from_dec_str('25514942427378518882041616545065271187265095759155217686057363902268374351523')!
assert a.rotate_left(182).str() == '88706376393829417451765793453791860419270208590599379720310994108668904859637'
}