Skip to main content
Log in

Mojo trait

Floorable

The Floorable trait describes a type that defines a floor operation.

Types that conform to Floorable will work with the builtin floor function. The floor operation always returns the same type as the input.

For example:

from math import Floorable, floor

@value
struct Complex(Floorable):
var re: Float64
var im: Float64

fn __floor__(self) -> Self:
return Self(floor(self.re), floor(self.im))
from math import Floorable, floor

@value
struct Complex(Floorable):
var re: Float64
var im: Float64

fn __floor__(self) -> Self:
return Self(floor(self.re), floor(self.im))

Implemented traits

AnyType, UnknownDestructibility

Methods

__floor__

__floor__(self: _Self) -> _Self

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

Returns:

The Int value itself.