math.unsigned #
Constants #
const uint256_max = Uint256{uint128_max, uint128_max}
const uint256_zero = Uint256{Uint128{}, Uint128{}}
const uint128_max = Uint128{18446744073709551615, 18446744073709551615}
const uint128_zero = Uint128{}
fn add_128 #
fn add_128(x Uint128, y Uint128, carry u64) (Uint128, u64)
add_128 return u + v and the carry
fn add_256 #
fn add_256(x Uint256, y Uint256, carry u64) (Uint256, u64)
add_256 - untested
fn div_128 #
fn div_128(hi Uint128, lo Uint128, y_ Uint128) (Uint128, Uint128)
div_128 returns u / v
fn mul_128 #
fn mul_128(x Uint128, y Uint128) (Uint128, Uint128)
mul_128 returns u x v
fn mul_256 #
fn mul_256(x Uint256, y Uint256) (Uint256, Uint256)
mul_256 - untested
fn sub_128 #
fn sub_128(x Uint128, y Uint128, borrow u64) (Uint128, u64)
sub_128 returns u - v and the borrow
fn sub_256 #
fn sub_256(x Uint256, y Uint256, borrow u64) (Uint256, u64)
sub_256 - untested
fn uint128_from_64 #
fn uint128_from_64(v u64) Uint128
uint128_from_64 converts v to a Uint128 value
fn uint128_from_dec_str #
fn uint128_from_dec_str(value string) !Uint128
unint_from_dec_str returns an error or new Uint128 from given string. The _
character is allowed as a separator.
fn uint128_new #
fn uint128_new(lo u64, hi u64) Uint128
uint128_new creates new Uint128 with given lo
and hi
fn uint256_from_128 #
fn uint256_from_128(v Uint128) Uint256
uint256_from_128 creates a new unsigned.Uint256
from the given Uint128 value
fn uint256_from_64 #
fn uint256_from_64(v u64) Uint256
uint256_from_64 creates a new unsigned.Uint256
from the given u64 value
fn uint256_from_dec_str #
fn uint256_from_dec_str(value string) !Uint256
uint256_from_dec_str creates a new unsigned.Uint256
from the given string if possible The _
character is allowed as a separator.
struct Uint128 #
struct Uint128 {
pub mut:
lo u64
hi u64
}
fn (Uint128) is_zero #
fn (u Uint128) is_zero() bool
is_zero returns true if u == 0
fn (Uint128) equals #
fn (u Uint128) equals(v Uint128) bool
equals returns true if u == v.
Uint128 values can be compared directly with ==, but use of the Equals method is preferred for consistency.
fn (Uint128) equals_64 #
fn (u Uint128) equals_64(v u64) bool
equals_64 returns true if u == v
fn (Uint128) cmp #
fn (u Uint128) cmp(v Uint128) int
cmp compares u and v and returns:
-1 if u < v 0 if u == v +1 if u > v
fn (Uint128) cmp_64 #
fn (u Uint128) cmp_64(v u64) int
cmp_64 compares u and v and returns:
-1 if u < v 0 if u == v +1 if u > v
fn (Uint128) and #
fn (u Uint128) and(v Uint128) Uint128
and returns u & v
fn (Uint128) and_64 #
fn (u Uint128) and_64(v u64) Uint128
and_64 returns u & v
fn (Uint128) or_ #
fn (u Uint128) or_(v Uint128) Uint128
or returns u | v
fn (Uint128) or_64 #
fn (u Uint128) or_64(v u64) Uint128
or returns u | v
fn (Uint128) xor #
fn (u Uint128) xor(v Uint128) Uint128
xor returns u ^ v
fn (Uint128) xor_64 #
fn (u Uint128) xor_64(v u64) Uint128
xor_64 returns u ^ v
fn (Uint128) add #
fn (u Uint128) add(v Uint128) Uint128
add returns u + v with wraparound semantics
fn (Uint128) add_64 #
fn (u Uint128) add_64(v u64) Uint128
add_64 returns u + v with wraparound semantics
fn (Uint128) sub #
fn (u Uint128) sub(v Uint128) Uint128
sub returns u - v with wraparound semantics
fn (Uint128) sub_64 #
fn (u Uint128) sub_64(v u64) Uint128
sub_64 returns u - v with wraparound semantics
fn (Uint128) mul #
fn (u Uint128) mul(v Uint128) Uint128
mul returns u * v with wraparound semantics
fn (Uint128) mul_64 #
fn (u Uint128) mul_64(v u64) Uint128
mul_64 returns u * v with wraparound semantics
fn (Uint128) overflowing_mul_64 #
fn (u Uint128) overflowing_mul_64(v u64) (Uint128, bool)
overflowing_mul_64 returns u x v even if result size > 64
fn (Uint128) overflowing_add_64 #
fn (u Uint128) overflowing_add_64(v u64) (Uint128, u64)
overflowing_add_64 returns u = v even if result size > 64
fn (Uint128) div #
fn (u Uint128) div(v Uint128) Uint128
div returns u / v
fn (Uint128) mod #
fn (u Uint128) mod(v Uint128) Uint128
mod returns r = u % v
fn (Uint128) mod_64 #
fn (u Uint128) mod_64(v u64) u64
mod_64 returns r = u % v
fn (Uint128) quo_rem_64 #
fn (u Uint128) quo_rem_64(v u64) (Uint128, u64)
quo_rem_64 returns q = u/v and r = u%v
fn (Uint128) quo_rem #
fn (u Uint128) quo_rem(v Uint128) (Uint128, Uint128)
quo_rem returns q = u/v and r = u%v
fn (Uint128) lsh #
fn (u Uint128) lsh(n u32) Uint128
lsh returns u << n
fn (Uint128) rsh #
fn (u Uint128) rsh(n u32) Uint128
rsh returns u >> n
fn (Uint128) leading_zeros #
fn (u Uint128) leading_zeros() int
leading_zeros returns the number of leading zero bits in u; the result is 128 for u == 0.
fn (Uint128) trailing_zeros #
fn (u Uint128) trailing_zeros() int
trailing_zeros returns the number of trailing zero bits in u; the result is 128 for u == 0.
fn (Uint128) ones_count #
fn (u Uint128) ones_count() int
ones_count returns the number of one bits ("population count" in u)
fn (Uint128) rotate_left #
fn (u Uint128) rotate_left(k int) Uint128
rotate_left returns the value of u rotated left by (k mod 128) bits.
fn (Uint128) rotate_right #
fn (u Uint128) rotate_right(k int) Uint128
rotate_right returns the value of u rotated right by (k mod 128) bits.
fn (Uint128) reverse #
fn (u Uint128) reverse() Uint128
reverse returns the value of u with its bits in reversed order.
fn (Uint128) reverse_bytes #
fn (u Uint128) reverse_bytes() Uint128
reverse_bytes returns the value of u with its bytes in reversed order.
fn (Uint128) not #
fn (u Uint128) not() Uint128
not returns a binary negation of the Uint128 value
fn (Uint128) len #
fn (u Uint128) len() int
len returns the minimum number of bits required to represent u; the result is 0 for u == 0.
fn (Uint128) str #
fn (u_ Uint128) str() string
string returns the base-10 representation of u as a string
fn (Uint128) put_bytes #
fn (u Uint128) put_bytes(mut b []u8)
put_bytes stores u in b in little-endian order
fn (Uint128) / #
fn (u Uint128) / (v Uint128) Uint128
/ -> returns u / v
fn (Uint128) % #
fn (u Uint128) % (v Uint128) Uint128
% -> returns u % v
fn (Uint128) + #
fn (u Uint128) + (v Uint128) Uint128
- -> returns u + v
fn (Uint128) - #
fn (u Uint128) - (v Uint128) Uint128
- -> returns u - v
fn (Uint128) * #
fn (u Uint128) * (v Uint128) Uint128
- -> returns u * v
fn (Uint128) < #
fn (u Uint128) < (v Uint128) bool
< -> returns true if u < v
struct Uint256 #
struct Uint256 {
pub mut:
lo Uint128 = uint128_zero // lower 128 bit half
hi Uint128 = uint128_zero // upper 128 bit half
}
Uint256 is an unsigned 256-bit number
fn (Uint256) is_zero #
fn (u Uint256) is_zero() bool
is_zero checks if specified Uint256 is zero
fn (Uint256) equals #
fn (u Uint256) equals(v Uint256) bool
equals checks if the two Uint256 values match one another
fn (Uint256) equals_128 #
fn (u Uint256) equals_128(v Uint128) bool
equals_128 checks if the Uint256 value matches the Uint128 value
fn (Uint256) cmp #
fn (u Uint256) cmp(v Uint256) int
cmp returns 1 if u is greater than v, -1 if u is less than v, or 0 if equal
fn (Uint256) cmp_128 #
fn (u Uint256) cmp_128(v Uint128) int
cmp_128 returns 1 if u is greater than v (Uint128), -1 if u is less than v, or 0 if equal
fn (Uint256) not #
fn (u Uint256) not() Uint256
not returns a binary negation of the Uint256 value
fn (Uint256) and #
fn (u Uint256) and(v Uint256) Uint256
and returns a Uint256 value that is the bitwise and of u and v
fn (Uint256) and_128 #
fn (u Uint256) and_128(v Uint128) Uint256
and_128 returns a Uint256 value that is the bitwise and of u and v, which is a Uint128
fn (Uint256) or_ #
fn (u Uint256) or_(v Uint256) Uint256
or_ returns a Uint256 value that is the bitwise or of u and v
fn (Uint256) or_128 #
fn (u Uint256) or_128(v Uint128) Uint256
or_128 returns a Uint256 value that is the bitwise or of u and v, which is a Uint128
fn (Uint256) xor #
fn (u Uint256) xor(v Uint256) Uint256
xor returns a Uint256 value that is the bitwise xor of u and v
fn (Uint256) xor_128 #
fn (u Uint256) xor_128(v Uint128) Uint256
xor_128 returns a Uint256 value that is the bitwise xor of u and v, which is a Uint128
fn (Uint256) add #
fn (u Uint256) add(v Uint256) Uint256
add returns a Uint256 that is equal to u+v
fn (Uint256) overflowing_add #
fn (u Uint256) overflowing_add(v Uint256) (Uint256, u64)
overflowing_add - untested
fn (Uint256) add_128 #
fn (u Uint256) add_128(v Uint128) Uint256
add_128 returns a Uint256 that is equal to u+v, v being a Uint128
fn (Uint256) sub #
fn (u Uint256) sub(v Uint256) Uint256
sub returns a Uint256 that is equal to u-v
fn (Uint256) sub_128 #
fn (u Uint256) sub_128(v Uint128) Uint256
sub_128 returns a Uint256 that is equal to u-v, v being a Uint128
fn (Uint256) mul #
fn (u Uint256) mul(v Uint256) Uint256
mul returns a Uint256 that is eqal to u*v
fn (Uint256) mul_128 #
fn (u Uint256) mul_128(v Uint128) Uint256
mul_128 returns a Uint256 that is eqal to u*v, v being a Uint128
fn (Uint256) quo_rem #
fn (u Uint256) quo_rem(v Uint256) (Uint256, Uint256)
quo_rem - untested
fn (Uint256) quo_rem_128 #
fn (u Uint256) quo_rem_128(v Uint128) (Uint256, Uint128)
quo_rem_128 - untested
fn (Uint256) quo_rem_64 #
fn (u Uint256) quo_rem_64(v u64) (Uint256, u64)
quo_rem_64 - untested
fn (Uint256) rsh #
fn (u Uint256) rsh(n_ u32) Uint256
rsh returns a new Uint256 that has been right bit shifted
fn (Uint256) lsh #
fn (u Uint256) lsh(n_ u32) Uint256
lsh returns a new Uint256 that has been left bit shifted
fn (Uint256) div #
fn (u Uint256) div(v Uint256) Uint256
div - untested
fn (Uint256) div_128 #
fn (u Uint256) div_128(v Uint128) Uint256
div_128 - untested
fn (Uint256) div_64 #
fn (u Uint256) div_64(v u64) Uint256
div_64 - untested
fn (Uint256) mod #
fn (u Uint256) mod(v Uint256) Uint256
mod - untested
fn (Uint256) mod_128 #
fn (u Uint256) mod_128(v Uint128) Uint128
mod_128 - untested
fn (Uint256) mod_64 #
fn (u Uint256) mod_64(v u64) u64
mod_64 - untested
fn (Uint256) rotate_left #
fn (u Uint256) rotate_left(k int) Uint256
rotate_left returns a new Uint256 that has been left bit shifted
fn (Uint256) rotate_right #
fn (u Uint256) rotate_right(k int) Uint256
rotate_right returns a new Uint256 that has been right bit shifted
fn (Uint256) len #
fn (u Uint256) len() int
len returns the length of the binary value without the leading zeros
fn (Uint256) leading_zeros #
fn (u Uint256) leading_zeros() int
leading_zeros returns the number of 0s at the beginning of the binary value of the Uint256 value [0, 256]
fn (Uint256) trailing_zeros #
fn (u Uint256) trailing_zeros() int
trailing_zeros returns the number of 0s at the end of the binary value of the Uint256 value [0,256]
fn (Uint256) ones_count #
fn (u Uint256) ones_count() int
ones_count returns the number of ones in the binary value of the Uint256 value
fn (Uint256) str #
fn (u_ Uint256) str() string
str returns the decimal representation of the unsigned integer
fn (Uint256) / #
fn (u Uint256) / (v Uint256) Uint256
/ -> returns u / v
fn (Uint256) % #
fn (u Uint256) % (v Uint256) Uint256
% -> returns u % v
fn (Uint256) + #
fn (u Uint256) + (v Uint256) Uint256
- -> returns u + v
fn (Uint256) - #
fn (u Uint256) - (v Uint256) Uint256
- -> returns u - v
fn (Uint256) * #
fn (u Uint256) * (v Uint256) Uint256
- -> returns u * v
fn (Uint256) < #
fn (u Uint256) < (v Uint256) bool
< -> returns true if u < v
- Constants
- fn add_128
- fn add_256
- fn div_128
- fn mul_128
- fn mul_256
- fn sub_128
- fn sub_256
- fn uint128_from_64
- fn uint128_from_dec_str
- fn uint128_new
- fn uint256_from_128
- fn uint256_from_64
- fn uint256_from_dec_str
- struct Uint128
- fn is_zero
- fn equals
- fn equals_64
- fn cmp
- fn cmp_64
- fn and
- fn and_64
- fn or_
- fn or_64
- fn xor
- fn xor_64
- fn add
- fn add_64
- fn sub
- fn sub_64
- fn mul
- fn mul_64
- fn overflowing_mul_64
- fn overflowing_add_64
- fn div
- fn mod
- fn mod_64
- fn quo_rem_64
- fn quo_rem
- fn lsh
- fn rsh
- fn leading_zeros
- fn trailing_zeros
- fn ones_count
- fn rotate_left
- fn rotate_right
- fn reverse
- fn reverse_bytes
- fn not
- fn len
- fn str
- fn put_bytes
- fn /
- fn %
- fn +
- fn -
- fn *
- fn <
- struct Uint256
- fn is_zero
- fn equals
- fn equals_128
- fn cmp
- fn cmp_128
- fn not
- fn and
- fn and_128
- fn or_
- fn or_128
- fn xor
- fn xor_128
- fn add
- fn overflowing_add
- fn add_128
- fn sub
- fn sub_128
- fn mul
- fn mul_128
- fn quo_rem
- fn quo_rem_128
- fn quo_rem_64
- fn rsh
- fn lsh
- fn div
- fn div_128
- fn div_64
- fn mod
- fn mod_128
- fn mod_64
- fn rotate_left
- fn rotate_right
- fn len
- fn leading_zeros
- fn trailing_zeros
- fn ones_count
- fn str
- fn /
- fn %
- fn +
- fn -
- fn *
- fn <