IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b1
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).

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

AnyType

Required methods

__trunc__

__trunc__(self: _Self) -> _Self

Return the truncated Int value, which is itself.

Returns:

_Self: The Int value itself.