8-bit unsigned integers with checked arithmetic
Most operations are available as built-in operators (e.g. 1 + 1
).
type Nat8 = Prim.Types.Nat8
8-bit natural numbers.
let toNat : Nat8 -> Nat
Conversion.
let fromNat : Nat -> Nat8
Conversion. Traps on overflow/underflow.
let fromIntWrap : Int -> Nat8
Conversion. Wraps on overflow/underflow.
func toText(x : Nat8) : Text
Returns the Text representation of x
.
func min(x : Nat8, y : Nat8) : Nat8
Returns the minimum of x
and y
.
func max(x : Nat8, y : Nat8) : Nat8
Returns the maximum of x
and y
.
func equal(x : Nat8, y : Nat8) : Bool
Returns x == y
.
func notEqual(x : Nat8, y : Nat8) : Bool
Returns x != y
.
func less(x : Nat8, y : Nat8) : Bool
Returns x < y
.
func lessOrEqual(x : Nat8, y : Nat8) : Bool
Returns x <= y
.
func greater(x : Nat8, y : Nat8) : Bool
Returns x > y
.
func greaterOrEqual(x : Nat8, y : Nat8) : Bool
Returns x >= y
.
func compare(x : Nat8, y : Nat8) : {#less; #equal; #greater}
Returns the order of x
and y
.
func add(x : Nat8, y : Nat8) : Nat8
Returns the sum of x
and y
, x + y
. Traps on overflow.
func sub(x : Nat8, y : Nat8) : Nat8
Returns the difference of x
and y
, x - y
. Traps on underflow.
func mul(x : Nat8, y : Nat8) : Nat8
Returns the product of x
and y
, x * y
. Traps on overflow.
func div(x : Nat8, y : Nat8) : Nat8
Returns the division of x by y
, x / y
.
Traps when y
is zero.
func rem(x : Nat8, y : Nat8) : Nat8
Returns the remainder of x
divided by y
, x % y
.
Traps when y
is zero.
func pow(x : Nat8, y : Nat8) : Nat8
Returns x
to the power of y
, x ** y
. Traps on overflow.
func bitnot(x : Nat8, y : Nat8) : Nat8
Returns the bitwise negation of x
, ^x
.
func bitand(x : Nat8, y : Nat8) : Nat8
Returns the bitwise and of x
and y
, x & y
.
func bitor(x : Nat8, y : Nat8) : Nat8
Returns the bitwise or of x
and y
, x \| y
.
func bitxor(x : Nat8, y : Nat8) : Nat8
Returns the bitwise exclusive or of x
and y
, x ^ y
.
func bitshiftLeft(x : Nat8, y : Nat8) : Nat8
Returns the bitwise shift left of x
by y
, x << y
.
func bitshiftRight(x : Nat8, y : Nat8) : Nat8
Returns the bitwise shift right of x
by y
, x >> y
.
func bitrotLeft(x : Nat8, y : Nat8) : Nat8
Returns the bitwise rotate left of x
by y
, x <<> y
.
func bitrotRight(x : Nat8, y : Nat8) : Nat8
Returns the bitwise rotate right of x
by y
, x <>> y
.
func bittest(x : Nat8, p : Nat) : Bool
Returns the value of bit p mod 8
in x
, (x & 2^(p mod 8)) == 2^(p mod 8)
.
func bitset(x : Nat8, p : Nat) : Nat8
Returns the value of setting bit p mod 8
in x
to 1
.
func bitclear(x : Nat8, p : Nat) : Nat8
Returns the value of clearing bit p mod 8
in x
to 0
.
func bitflip(x : Nat8, p : Nat) : Nat8
Returns the value of flipping bit p mod 8
in x
.
let bitcountNonZero : (x : Nat8) -> Nat8
Returns the count of non-zero bits in x
.
let bitcountLeadingZero : (x : Nat8) -> Nat8
Returns the count of leading zero bits in x
.
let bitcountTrailingZero : (x : Nat8) -> Nat8
Returns the count of trailing zero bits in x
.
func addWrap(x : Nat8, y : Nat8) : Nat8
Returns the sum of x
and y
, x +% y
. Wraps on overflow.
func subWrap(x : Nat8, y : Nat8) : Nat8
Returns the difference of x
and y
, x -% y
. Wraps on underflow.
func mulWrap(x : Nat8, y : Nat8) : Nat8
Returns the product of x
and y
, x *% y
. Wraps on overflow.
func powWrap(x : Nat8, y : Nat8) : Nat8
Returns x
to the power of y
, x **% y
. Wraps on overflow.