std/math/bits
Globals
const UintSize
Is the size of a uint in bits.
Functions
fn LeadingZeros(x: uint): int
Returns the number of leading zero bits in x; the result is UintSize for x == 0.
fn LeadingZeros8(x: u8): int
Returns the number of leading zero bits in x; the result is 8 for x == 0.
fn LeadingZeros16(x: u16): int
Returns the number of leading zero bits in x; the result is 16 for x == 0.
fn LeadingZeros32(x: u32): int
Returns the number of leading zero bits in x; the result is 32 for x == 0.
fn LeadingZeros64(x: u64): int
Returns the number of leading zero bits in x; the result is 64 for x == 0.
fn TrailingZeros(x: uint): int
Returns the number of trailing zero bits in x; the result is UintSize for x == 0.
fn TrailingZeros8(x: u8): int
Returns the number of trailing zero bits in x; the result is 8 for x == 0.
fn TrailingZeros16(x: u16): int
Returns the number of trailing zero bits in x; the result is 16 for x == 0.
fn TrailingZeros32(x: u32): int
Returns the number of trailing zero bits in x; the result is 32 for x == 0.
fn TrailingZeros64(x: u64): int
Returns the number of trailing zero bits in x; the result is 64 for x == 0.
fn OnesCount(x: uint): int
Returns the number of one bits ("population count") in x.
fn OnesCount8(x: u8): int
Returns the number of one bits ("population count") in x.
fn OnesCount16(x: u16): int
Returns the number of one bits ("population count") in x.
fn OnesCount32(x: u32): int
Returns the number of one bits ("population count") in x.
fn OnesCount64(mut x: u64): int
Returns the number of one bits ("population count") in x.
fn RotateLeft(x: uint, k: int): uint
Returns the value of x rotated left by (k mod UintSize) bits. To rotate x right by k bits, call RotateLeft(x, -k).
TIP
This function's execution time does not depend on the inputs.
fn RotateLeft8(x: u8, k: int): u8
Returns the value of x rotated left by (k mod 8) bits. To rotate x right by k bits, call RotateLeft8(x, -k).
TIP
This function's execution time does not depend on the inputs.
fn RotateLeft16(x: u16, k: int): u16
Returns the value of x rotated left by (k mod 16) bits. To rotate x right by k bits, call RotateLeft16(x, -k).
TIP
This function's execution time does not depend on the inputs.
fn RotateLeft32(x: u32, k: int): u32
Returns the value of x rotated left by (k mod 32) bits. To rotate x right by k bits, call RotateLeft32(x, -k).
TIP
This function's execution time does not depend on the inputs.
fn RotateLeft64(x: u64, k: int): u64
Returns the value of x rotated left by (k mod 64) bits. To rotate x right by k bits, call RotateLeft64(x, -k).
TIP
This function's execution time does not depend on the inputs.
fn Reverse(x: uint): uint
Returns the value of x with its bits in reversed order.
fn Reverse8(x: u8): u8
Returns the value of x with its bits in reversed order.
fn Reverse16(x: u16): u16
Returns the value of x with its bits in reversed order.
fn Reverse32(mut x: u32): u32
Returns the value of x with its bits in reversed order.
fn Reverse64(mut x: u64): u64
Returns the value of x with its bits in reversed order.
fn ReverseBytes(x: uint): uint
Returns the value of x with its bytes in reversed order.
TIP
This function's execution time does not depend on the inputs.
fn ReverseBytes16(x: u16): u16
Returns the value of x with its bytes in reversed order.
TIP
This function's execution time does not depend on the inputs.
fn ReverseBytes32(mut x: u32): u32
Returns the value of x with its bytes in reversed order.
TIP
This function's execution time does not depend on the inputs.
fn ReverseBytes64(mut x: u64): u64
Returns the value of x with its bytes in reversed order.
TIP
This function's execution time does not depend on the inputs.
fn Len(x: uint): int
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
fn Len8(x: u8): int
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
fn Len16(mut x: u16): (n: int)
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
fn Len32(mut x: u32): (n: int)
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
fn Len64(mut x: u64): (n: int)
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
fn Add(x: uint, y: uint, carry: uint): (sum: uint, carry_out: uint)
Returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.
TIP
This function's execution time does not depend on the inputs.
fn Add32(x: u32, y: u32, carry: u32): (sum: u32, carryOut: u32)
Returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.
TIP
This function's execution time does not depend on the inputs.
fn Add64(x: u64, y: u64, carry: u64): (sum: u64, carryOut: u64)
Returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.
TIP
This function's execution time does not depend on the inputs.
fn Sub(x: uint, y: uint, borrow: uint): (diff: uint, borrowOut: uint)
Returns the difference of x, y and borrow, diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.
TIP
This function's execution time does not depend on the inputs.
fn Sub32(x: u32, y: u32, borrow: u32): (diff: u32, borrowOut: u32)
Returns the difference of x, y and borrow, diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.
TIP
This function's execution time does not depend on the inputs.
fn Sub64(x: u64, y: u64, borrow: u64): (diff: u64, borrowOut: u64)
Returns the difference of x, y and borrow: diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.
TIP
This function's execution time does not depend on the inputs.
fn Mul(x: uint, y: uint): (hi: uint, lo: uint)
Returns the 64-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.
TIP
This function's execution time does not depend on the inputs.
fn Mul32(x: u32, y: u32): (hi: u32, lo: u32)
Returns the 64-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.
TIP
This function's execution time does not depend on the inputs.
fn Mul64(x: u64, y: u64): (hi: u64, lo: u64)
Returns the 128-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.
TIP
This function's execution time does not depend on the inputs.
fn Div(hi: uint, lo: uint, y: uint): (quo: uint, rem: uint)
Returns the quotient and remainder of (hi, lo) divided by y:
quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo.
div panics for y == 0 (division by zero) or y <= hi (quotient overflow).
fn Div32(hi: u32, lo: u32, y: u32): (quo: u32, rem: u32)
Returns the quotient and remainder of (hi, lo) divided by y:
quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo.
div32 panics for y == 0 (division by zero) or y <= hi (quotient overflow).
fn Div64(hi: u64, lo: u64, mut y: u64): (quo: u64, rem: u64)
Returns the quotient and remainder of (hi, lo) divided by y:
quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo.
div64 panics for y == 0 (division by zero) or y <= hi (quotient overflow).
fn Rem(hi: uint, lo: uint, y: uint): uint
Returns the remainder of (hi, lo) divided by y. rem panics for y == 0 (division by zero) but, unlike div, it doesn't panic on a quotient overflow.
fn Rem32(hi: u32, lo: u32, y: u32): u32
Returns the remainder of (hi, lo) divided by y. rem32 panics for y == 0 (division by zero) but, unlike div32, it doesn't panic on a quotient overflow.
fn Rem64(hi: u64, lo: u64, y: u64): u64
Returns the remainder of (hi, lo) divided by y. rem64 panics for y == 0 (division by zero) but, unlike div64, it doesn't panic on a quotient overflow.