Mojo trait
Truncable
The Truncable trait describes a type that defines a truncation operation.
Types that conform to Truncable will work with the builtin trunc
function. The truncation operation always returns the same type as the
input.
For example:
from std.math import Truncable, trunc
@fieldwise_init
struct Complex(Truncable, ImplicitlyCopyable):
var re: Float64
var im: Float64
def __trunc__(self) -> Self:
return Self(trunc(self.re), trunc(self.im))Implemented traitsโ
Required methodsโ
__trunc__โ
__trunc__(self: _Self) -> _Self
Return the truncated Int value, which is itself.
Returns:
_Self: The Int value itself.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!