Skip to main content

Mojo trait

Floatable

The Floatable trait describes a type that can be converted to a Float64.

This trait requires the type to implement the __float__() method.

For example:

struct Foo(Floatable):
    var i: Float64

    fn __float__(self) -> Float64:
        return self.i

A Foo can now be converted to a Float64:

var f = Float64(Foo(5.5))

Note: If the __float__() method can raise an error, use the FloatableRaising trait instead.

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

__float__

__float__(self: _Self) -> SIMD[float64, 1]

Get the float point representation of the value.

Returns:

SIMD: The float point representation of the value.

Was this page helpful?