mirror of
https://github.com/vlang/v.git
synced 2025-09-09 23:39:39 -04:00
math.unsigned: fix rotate_left() for uint256, add test (#24872)
This commit is contained in:
parent
e850f6c678
commit
03e72a4856
@ -348,7 +348,7 @@ pub fn (u Uint256) rotate_left(k int) Uint256 {
|
|||||||
return Uint256{u.hi, u.lo}
|
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
|
n -= 64
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
@ -303,3 +303,8 @@ fn test_lsh() {
|
|||||||
assert a.lsh(200).str() == '197653379443855803891661337357963000110230968235283518742069248'
|
assert a.lsh(200).str() == '197653379443855803891661337357963000110230968235283518742069248'
|
||||||
assert a.lsh(300) == unsigned.uint256_zero
|
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'
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user