Mojo trait
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 Point(Absable):
var x: Float64
var y: Float64
fn __abs__(self) -> Self:
return sqrt(self.x * self.x + self.y * self.y)
Implemented traits
AnyType
,
UnknownDestructibility
Aliases
__del__is_trivial
alias __del__is_trivial
A flag (often compiler generated) to indicate whether the implementation of __del__
is trivial.
The implementation of __del__
is considered to be trivial if:
- The struct has a compiler-generated trivial destructor and all its fields
have a trivial
__del__
method.
In practice, it means that the __del__
can be considered as no-op.
Methods
__abs__
__abs__(self: _Self) -> _Self
Get the absolute value of this instance.
Returns:
_Self
: The absolute value of the instance.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!