math.unsigned: add uint256_new() function and tests (#24837)

This commit is contained in:
Mike 2025-07-02 22:30:59 +03:00 committed by GitHub
parent 3eb04e346c
commit c989f9bb78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View File

@ -170,3 +170,7 @@ fn test_separators() {
assert with == without
}
}
fn test_new() {
assert unsigned.uint128_new(max_u64, max_u64) == unsigned.uint128_max
}

View File

@ -22,6 +22,11 @@ pub fn uint256_from_64(v u64) Uint256 {
return uint256_from_128(uint128_from_64(v))
}
// uint256_new creates new Uint256 with given `lo` and `hi`
pub fn uint256_new(lo Uint128, hi Uint128) Uint256 {
return Uint256{lo, hi}
}
// is_zero checks if specified Uint256 is zero
pub fn (u Uint256) is_zero() bool {
return u.lo.is_zero() && u.hi.is_zero()

View File

@ -276,3 +276,7 @@ fn test_separators() {
assert with == without
}
}
fn test_new() {
assert unsigned.uint256_new(unsigned.uint128_max, unsigned.uint128_max) == unsigned.uint256_max
}