Skip to main content
Log in

Mojo trait

IntLike

The IntLike trait is a tag for Int or UInt. This allows writing functions that works on either.

Implemented traits

Absable, AnyType, Ceilable, Comparable, EqualityComparable, Floorable, Formattable, Powable, Stringable, Truncable

Methods

__lt__

__lt__(self: T, rhs: T) -> Bool

Define whether self is less than rhs.

Args:

  • rhs (T): The right hand side of the comparison.

Returns:

True if self is less than rhs.

__le__

__le__(self: T, rhs: T) -> Bool

Define whether self is less than or equal to rhs.

Args:

  • rhs (T): The right hand side of the comparison.

Returns:

True if self is less than or equal to rhs.

__eq__

__eq__(self: T, other: T) -> Bool

Define whether two instances of the object are equal to each other.

Args:

  • other (T): Another instance of the same type.

Returns:

True if the instances are equal according to the type's definition of equality, False otherwise.

__ne__

__ne__(self: T, other: T) -> Bool

Define whether two instances of the object are not equal to each other.

Args:

  • other (T): Another instance of the same type.

Returns:

True if the instances are not equal according to the type's definition of equality, False otherwise.

__gt__

__gt__(self: T, rhs: T) -> Bool

Define whether self is greater than rhs.

Args:

  • rhs (T): The right hand side of the comparison.

Returns:

True if self is greater than rhs.

__ge__

__ge__(self: T, rhs: T) -> Bool

Define whether self is greater than or equal to rhs.

Args:

  • rhs (T): The right hand side of the comparison.

Returns:

True if self is greater than or equal to rhs.

__pow__

__pow__(self: T, exp: T) -> T

Return the value raised to the power of the given exponent.

Args:

  • exp (T): The exponent value.

Returns:

The value of self raised to the power of exp.

__mlir_index__

__mlir_index__(self: T) -> index

Convert to index.

Returns:

The corresponding __mlir_type.index value.

__abs__

__abs__(self: T) -> T

Get the absolute value of this instance.

Returns:

The absolute value of the instance.

__ceil__

__ceil__(self: T) -> T

Return the ceiling of the Int value, which is itself.

Returns:

The Int value itself.

__floor__

__floor__(self: T) -> T

Return the floor of the Int value, which is itself.

Returns:

The Int value itself.

format_to

format_to(self: T, inout writer: Formatter)

Formats the string representation of this type to the provided formatter.

Args:

  • writer (Formatter): The formatter to write to.

__str__

__str__(self: T) -> String

Get the string representation of the type.

Returns:

The string representation of the type.

__trunc__

__trunc__(self: T) -> T

Return the truncated Int value, which is itself.

Returns:

The Int value itself.

Was this page helpful?