float_literal

Module

Implements the FloatLiteral class.

These are Mojo built-ins, so you don’t need to import them.

FloatLiteral

Mojo floating point literal type.

Aliases:

  • fp_type = scalar<f64>

Fields:

  • value (scalar<f64>): The underlying storage for the floating point value.

Functions:

__init__

__init__(value: Self) -> Self

Forwarding constructor.

Args:

  • value (Self): The double value.

Returns:

The value.

__init__(value: f64) -> Self

Create a double value from a builtin MLIR f64 value.

Args:

  • value (f64): The underlying MLIR value.

Returns:

A double value.

__init__(value: Int) -> Self

Convert an integer to a double value.

Args:

  • value (Int): The integer value.

Returns:

The integer value as a double.

__init__(value: IntLiteral) -> Self

Convert an IntLiteral to a double value.

Args:

  • value (IntLiteral): The IntLiteral value.

Returns:

The integer value as a double.

__init__(value: scalar<f64>) -> Self

__bool__

__bool__(self: Self) -> Bool

A double value is true if it is non-zero.

Returns:

True if non-zero.

__neg__

__neg__(self: Self) -> Self

Return the negation of the double value.

Returns:

The negated double value.

__lt__

__lt__(self: Self, rhs: Self) -> Bool

Less than comparison.

Args:

  • rhs (Self): The value to compare.

Returns:

True if this value is less than rhs.

__le__

__le__(self: Self, rhs: Self) -> Bool

Less than or equal to comparison.

Args:

  • rhs (Self): The value to compare.

Returns:

True if this value is less than or equal to rhs.

__eq__

__eq__(self: Self, rhs: Self) -> Bool

Compare for equality.

Args:

  • rhs (Self): The value to compare.

Returns:

True if they are equal.

__ne__

__ne__(self: Self, rhs: Self) -> Bool

Compare for inequality.

Args:

  • rhs (Self): The value to compare.

Returns:

True if they are not equal.

__gt__

__gt__(self: Self, rhs: Self) -> Bool

Greater than comparison.

Args:

  • rhs (Self): The value to compare.

Returns:

True if this value is greater than rhs.

__ge__

__ge__(self: Self, rhs: Self) -> Bool

Greater than or equal to comparison.

Args:

  • rhs (Self): The value to compare.

Returns:

True if this value is greater than or equal to rhs.

__add__

__add__(self: Self, rhs: Self) -> Self

Add two doubles.

Args:

  • rhs (Self): The value to add.

Returns:

The sum of the two values.

__sub__

__sub__(self: Self, rhs: Self) -> Self

Subtract two doubles.

Args:

  • rhs (Self): The value to subtract.

Returns:

The difference of the two values.

__mul__

__mul__(self: Self, rhs: Self) -> Self

Multiply two doubles.

Args:

  • rhs (Self): The value to multiply.

Returns:

The product of the two values.

__truediv__

__truediv__(self: Self, rhs: Self) -> Self

Divide two doubles.

Args:

  • rhs (Self): The value to divide.

Returns:

The quotient of the two values.

__floordiv__

__floordiv__(self: Self, rhs: Self) -> Self

Divide two doubles and round towards negative infinity.

Args:

  • rhs (Self): The value to divide.

Returns:

The quotient of the two values rounded towards negative infinity.

__mod__

__mod__(self: Self, rhs: Self) -> Self

Compute the remainder of dividing by a value.

Args:

  • rhs (Self): The divisor.

Returns:

The remainder of the division operation.

__pow__

__pow__(self: Self, rhs: Self) -> Self

Compute the power.

Args:

  • rhs (Self): The exponent.

Returns:

The current value raised to the exponent.

__radd__

__radd__(self: Self, rhs: Self) -> Self

Reversed addition operator.

Args:

  • rhs (Self): The value to add.

Returns:

The sum of this and the given value.

__rsub__

__rsub__(self: Self, rhs: Self) -> Self

Reversed subtraction operator.

Args:

  • rhs (Self): The value to subtract from.

Returns:

The result of subtracting this from the given value.

__rmul__

__rmul__(self: Self, rhs: Self) -> Self

Reversed multiplication operator.

Args:

  • rhs (Self): The value to multiply.

Returns:

The product of the given number and this.

__rtruediv__

__rtruediv__(self: Self, rhs: Self) -> Self

Reversed division.

Args:

  • rhs (Self): The value to be divided by this.

Returns:

The result of dividing the given value by this.

__rfloordiv__

__rfloordiv__(self: Self, rhs: Self) -> Self

Reversed floor division.

Args:

  • rhs (Self): The value to be floor-divided by this.

Returns:

The result of dividing the given value by this, modulo any remainder.

__rmod__

__rmod__(self: Self, rhs: Self) -> Self

Reversed remainder.

Args:

  • rhs (Self): The divisor.

Returns:

The remainder after dividing the given value by this.

__rpow__

__rpow__(self: Self, rhs: Self) -> Self

Reversed power.

Args:

  • rhs (Self): The number to be raised to the power of this.

Returns:

The result of raising the given number by this value.

__iadd__

__iadd__(inout self: Self, rhs: Self)

In-place addition operator.

Args:

  • rhs (Self): The value to add.

__isub__

__isub__(inout self: Self, rhs: Self)

In-place subtraction operator.

Args:

  • rhs (Self): The value to subtract.

__imul__

__imul__(inout self: Self, rhs: Self)

In-place multiplication operator.

Args:

  • rhs (Self): The value to multiply.

__itruediv__

__itruediv__(inout self: Self, rhs: Self)

In-place division.

Args:

  • rhs (Self): The value to divide.

__ifloordiv__

__ifloordiv__(inout self: Self, rhs: Self)

In-place floor division.

Args:

  • rhs (Self): The value to divide.

__imod__

__imod__(inout self: Self, rhs: Self)

In-place remainder.

Args:

  • rhs (Self): The divisor.

__ipow__

__ipow__(inout self: Self, rhs: Self)

In-place power.

Args:

  • rhs (Self): The exponent.

to_int

to_int(self: Self) -> Int

Casts to the floating point value to an Int. If there is a fractional component, then the value is truncated towards zero.

Returns:

The value as an integer.

__int__

__int__(self: Self) -> Int

Casts to the floating point value to an Int. If there is a fractional component, then the value is truncated towards zero.

Returns:

The value as an integer.