For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
Absable
The Absable trait describes a type that defines an absolute value operation.
Types that conform to Absable will work with the builtin abs function.
The absolute value operation always returns the same type as the input.
For example:
struct Celsius(Absable):
var degrees: Float64
def __init__(out self, degrees: Float64):
self.degrees = degrees
def __abs__(self) -> Self:
return Self(abs(self.degrees))
Implemented traits
Required methods
__abs__
__abs__(self: _Self) -> _Self
Get the absolute value of this instance.
Returns:
_Self: The absolute value of the instance.