Mojo struct
UInt
This type represents an unsigned integer.
An unsigned integer is represents a positive integral number.
The size of this unsigned integer is platform-dependent.
If you wish to use a fixed size unsigned integer, consider using
UInt8
, UInt16
, UInt32
, or UInt64
.
Aliasesβ
MAX = __sub__(__lshift__(1, bitwidthof[::DType,__mlir_type.!kgen.target]()), 1)
: Returns the maximum integer value.MIN = 0
: Returns the minimum value of type.
Fieldsβ
- βvalue (
index
): The underlying storage for the integer value.
Implemented traitsβ
Absable
,
AnyType
,
Ceilable
,
Comparable
,
Copyable
,
EqualityComparable
,
Floorable
,
Formattable
,
IntLike
,
Movable
,
Powable
,
Stringable
,
Truncable
Methodsβ
__init__
β
__init__(inout self: Self)
Default constructor that produces zero.
__init__(inout self: Self, value: index)
Construct UInt from the given index value.
Args:
- βvalue (
index
): The init value.
__init__(inout self: Self, value: Int)
Construct UInt from the given index value.
Args:
- βvalue (
Int
): The init value.
__init__(inout self: Self, value: IntLiteral)
Construct UInt from the given IntLiteral value.
Args:
- βvalue (
IntLiteral
): The init value.
__bool__
β
__bool__(self: Self) -> Bool
Convert this Int to Bool.
Returns:
False Bool value if the value is equal to 0 and True otherwise.
__pos__
β
__pos__(self: Self) -> Self
Return +self.
Returns:
The +self value.
__lt__
β
__lt__(self: Self, rhs: Self) -> Bool
Return whether this UInt is strictly less than another.
Args:
- βrhs (
Self
): The other UInt to compare against.
Returns:
True if this UInt is less than the other UInt and False otherwise.
__lt__(self: Self, rhs: Int) -> Bool
Compare this Int to the RHS using LT comparison.
Args:
- βrhs (
Int
): The other Int to compare against.
Returns:
True if this Int is less-than the RHS Int and False otherwise.
__le__
β
__le__(self: Self, rhs: Self) -> Bool
Compare this Int to the RHS using LE comparison.
Args:
- βrhs (
Self
): The other UInt to compare against.
Returns:
True if this Int is less-than the RHS Int and False otherwise.
__eq__
β
__eq__(self: Self, rhs: Self) -> Bool
Compare this UInt to the RHS using EQ comparison.
Args:
- βrhs (
Self
): The other UInt to compare against.
Returns:
True if this UInt is equal to the RHS UInt and False otherwise.
__ne__
β
__ne__(self: Self, rhs: Self) -> Bool
Compare this UInt to the RHS using NE comparison.
Args:
- βrhs (
Self
): The other UInt to compare against.
Returns:
True if this UInt is non-equal to the RHS UInt and False otherwise.
__gt__
β
__gt__(self: Self, rhs: Self) -> Bool
Return whether this UInt is strictly greater than another.
Args:
- βrhs (
Self
): The other UInt to compare against.
Returns:
True if this UInt is greater than the other UInt and False otherwise.
__ge__
β
__ge__(self: Self, rhs: Self) -> Bool
Return whether this UInt is greater than or equal to another.
Args:
- βrhs (
Self
): The other UInt to compare against.
Returns:
True if this UInt is greater than or equal to the other UInt and False otherwise.
__add__
β
__add__(self: Self, rhs: Self) -> Self
Return self + rhs
.
Args:
- βrhs (
Self
): The value to add.
Returns:
self + rhs
value.
__sub__
β
__sub__(self: Self, rhs: Self) -> Self
Return self - rhs
.
Args:
- βrhs (
Self
): The value to subtract.
Returns:
self - rhs
value.
__mul__
β
__mul__(self: Self, rhs: Self) -> Self
Return self * rhs
.
Args:
- βrhs (
Self
): The value to multiply with.
Returns:
self * rhs
value.
__truediv__
β
__truediv__(self: Self, rhs: Self) -> SIMD[float64, 1]
Return the floating point division of self
and rhs
.
Args:
- βrhs (
Self
): The value to divide on.
Returns:
float(self)/float(rhs)
value.
__floordiv__
β
__floordiv__(self: Self, rhs: Self) -> Self
Return the division of self
and rhs
rounded down to the nearest integer.
Args:
- βrhs (
Self
): The value to divide on.
Returns:
floor(self/rhs)
value.
__mod__
β
__mod__(self: Self, rhs: Self) -> Self
Return the remainder of self divided by rhs.
Args:
- βrhs (
Self
): The value to divide on.
Returns:
The remainder of dividing self by rhs.
__pow__
β
__pow__(self: Self, exp: Self) -> Self
Return the value raised to the power of the given exponent.
Computes the power of an integer using the Russian Peasant Method.
Args:
- βexp (
Self
): The exponent value.
Returns:
The value of self
raised to the power of exp
.
__lshift__
β
__lshift__(self: Self, rhs: Self) -> Self
Return self << rhs
.
Args:
- βrhs (
Self
): The value to shift with.
Returns:
self << rhs
.
__rshift__
β
__rshift__(self: Self, rhs: Self) -> Self
Return self >> rhs
.
Args:
- βrhs (
Self
): The value to shift with.
Returns:
self >> rhs
.
__and__
β
__and__(self: Self, rhs: Self) -> Self
Return self & rhs
.
Args:
- βrhs (
Self
): The RHS value.
Returns:
self & rhs
.
__or__
β
__or__(self: Self, rhs: Self) -> Self
Return self | rhs
.
Args:
- βrhs (
Self
): The RHS value.
Returns:
self | rhs
.
__xor__
β
__xor__(self: Self, rhs: Self) -> Self
Return self ^ rhs
.
Args:
- βrhs (
Self
): The RHS value.
Returns:
self ^ rhs
.
__radd__
β
__radd__(self: Self, value: Self) -> Self
Return value + self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value + self
.
__rsub__
β
__rsub__(self: Self, value: Self) -> Self
Return value - self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value - self
.
__rmul__
β
__rmul__(self: Self, value: Self) -> Self
Return value * self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value * self
.
__rfloordiv__
β
__rfloordiv__(self: Self, value: Self) -> Self
Return value // self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value // self
.
__rmod__
β
__rmod__(self: Self, value: Self) -> Self
Return value % self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value % self
.
__rpow__
β
__rpow__(self: Self, value: Self) -> Self
Return pow(value,self)
.
Args:
- βvalue (
Self
): The other value.
Returns:
pow(value,self)
.
__rlshift__
β
__rlshift__(self: Self, value: Self) -> Self
Return value << self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value << self
.
__rrshift__
β
__rrshift__(self: Self, value: Self) -> Self
Return value >> self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value >> self
.
__rand__
β
__rand__(self: Self, value: Self) -> Self
Return value & self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value & self
.
__ror__
β
__ror__(self: Self, value: Self) -> Self
Return value | self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value | self
.
__rxor__
β
__rxor__(self: Self, value: Self) -> Self
Return value ^ self
.
Args:
- βvalue (
Self
): The other value.
Returns:
value ^ self
.
__iadd__
β
__iadd__(inout self: Self, rhs: Self)
Compute self + rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__isub__
β
__isub__(inout self: Self, rhs: Self)
Compute self - rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__imul__
β
__imul__(inout self: Self, rhs: Self)
Compute self*rhs and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__itruediv__
β
__itruediv__(inout self: Self, rhs: Self)
Compute self / rhs
, convert to int, and save the result in self.
Since floor(self / rhs)
is equivalent to self // rhs
, this yields
the same as __ifloordiv__
.
Args:
- βrhs (
Self
): The RHS value.
__ifloordiv__
β
__ifloordiv__(inout self: Self, rhs: Self)
Compute self // rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__imod__
β
__imod__(inout self: Self, rhs: Self)
Compute self % rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__ipow__
β
__ipow__(inout self: Self, rhs: Self)
Compute pow(self, rhs)
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__ilshift__
β
__ilshift__(inout self: Self, rhs: Self)
Compute self << rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__irshift__
β
__irshift__(inout self: Self, rhs: Self)
Compute self >> rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__iand__
β
__iand__(inout self: Self, rhs: Self)
Compute self & rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__ixor__
β
__ixor__(inout self: Self, rhs: Self)
Compute self ^ rhs
and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__ior__
β
__ior__(inout self: Self, rhs: Self)
Compute self|rhs and save the result in self.
Args:
- βrhs (
Self
): The RHS value.
__mlir_index__
β
__mlir_index__(self: Self) -> index
Convert to index.
Returns:
The corresponding __mlir_type.index value.
__str__
β
__str__(self: Self) -> String
Convert this UInt to a string.
A small example.
var x = UInt(50)
var x_as_string = str(x) # x_as_string = "50"
var x = UInt(50)
var x_as_string = str(x) # x_as_string = "50"
Returns:
The string representation of this UInt.
format_to
β
format_to(self: Self, inout writer: Formatter)
Formats this integer to the provided formatter.
Args:
- βwriter (
Formatter
): The formatter to write to.
__repr__
β
__repr__(self: Self) -> String
Convert this UInt to a string.
A small example.
var x = UInt(50)
var x_as_string = repr(x) # x_as_string = "UInt(50)"
var x = UInt(50)
var x_as_string = repr(x) # x_as_string = "UInt(50)"
Returns:
The string representation of this UInt.
__divmod__
β
__divmod__(self: Self, rhs: Self) -> Tuple[UInt, UInt]
Computes both the quotient and remainder using integer division.
Args:
- βrhs (
Self
): The value to divide on.
Returns:
The quotient and remainder as a Tuple(self // rhs, self % rhs)
.
__index__
β
__index__(self: Self) -> Self
Return self converted to an unsigned integer, if self is suitable for use as an index into a list.
For Int type this is simply the value.
Returns:
The corresponding Int value.
__ceil__
β
__ceil__(self: Self) -> Self
Return the ceiling of the UInt value, which is itself.
Returns:
The UInt value itself.
__floor__
β
__floor__(self: Self) -> Self
Return the floor of the UInt value, which is itself.
Returns:
The UInt value itself.
__round__
β
__round__(self: Self) -> Self
Return the rounded value of the UInt value, which is itself.
Returns:
The UInt value itself.
__round__(self: Self, ndigits: Self) -> Self
Return the rounded value of the UInt value, which is itself.
Args:
- βndigits (
Self
): The number of digits to round to.
Returns:
The UInt value itself if ndigits >= 0 else the rounded value.
__trunc__
β
__trunc__(self: Self) -> Self
Return the truncated UInt value, which is itself.
Returns:
The Int value itself.
__abs__
β
__abs__(self: Self) -> Self
Return the absolute value of the UInt value.
Returns:
The absolute value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?