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: Nightly
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).

FloatLiteral

struct FloatLiteral[value: __mlir_type.`!pop.float_literal`]

Mojo floating point literal type.

Parameters

  • value (__mlir_type.`!pop.float_literal`): The underlying infinite precision floating point value.

Implemented traits

AnyType, Boolable, Copyable, Defaultable, Floatable, ImplicitlyCopyable, ImplicitlyDestructible, Intable, Movable, RegisterPassable, TrivialRegisterPassable, Writable

comptime members

infinity

comptime infinity = inf

Positive infinity value.

nan

comptime nan

Not a number (NaN) value.

negative_infinity

comptime negative_infinity = -inf

Negative infinity value.

negative_zero

comptime negative_zero = -0.0

Negative zero value.

Methods

__init__

def __init__() -> Self

Create a FloatLiteral for any parameter value.

@implicit def __init__(_value: IntLiteral) -> FloatLiteral[#pop.int_to_float_literal<*"_value.value`2x">]

Convert an IntLiteral to a FloatLiteral value.

Args:

Returns:

FloatLiteral[#pop.int_to_float_literal<*"_value.value`2x">]

__bool__

def __bool__(self) -> Bool

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

Returns:

Bool: True if non-zero.

__neg__

def __neg__(self) -> FloatLiteral[#pop.float_literal_bin<mul value, #pop.float_literal<-1|1>>]

Return the negation of the FloatLiteral value.

Returns:

FloatLiteral[#pop.float_literal_bin<mul value, #pop.float_literal<-1|1>>]: The negated FloatLiteral value.

__lt__

def __lt__(self, rhs: FloatLiteral) -> Bool

Less than comparison.

Args:

Returns:

Bool: True if this value is less than rhs.

__le__

def __le__(self, rhs: FloatLiteral) -> Bool

Less than or equal to comparison.

Args:

Returns:

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

__eq__

def __eq__(self, rhs: FloatLiteral) -> Bool

Compare for equality.

Args:

Returns:

Bool: True if they are equal.

__ne__

def __ne__(self, rhs: FloatLiteral) -> Bool

Compare for inequality.

Args:

Returns:

Bool: True if they are not equal.

__gt__

def __gt__(self, rhs: FloatLiteral) -> Bool

Greater than comparison.

Args:

Returns:

Bool: True if this value is greater than rhs.

__ge__

def __ge__(self, rhs: FloatLiteral) -> Bool

Greater than or equal to comparison.

Args:

Returns:

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

__add__

def __add__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<add value, *"rhs.value`2x">]

Add two FloatLiterals.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<add value, *"rhs.value`2x">]: The sum of the two values.

__sub__

def __sub__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<sub value, *"rhs.value`2x">]

Subtract two FloatLiterals.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<sub value, *"rhs.value`2x">]: The difference of the two values.

__mul__

def __mul__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<mul value, *"rhs.value`2x">]

Multiply two FloatLiterals.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<mul value, *"rhs.value`2x">]: The product of the two values.

__truediv__

def __truediv__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<truediv value, *"rhs.value`2x">]

Divide two FloatLiterals.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<truediv value, *"rhs.value`2x">]: The quotient of the two values.

__floordiv__

def __floordiv__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<floordiv value, *"rhs.value`2x">]

Returns self divided by rhs, rounded down to the nearest integer.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<floordiv value, *"rhs.value`2x">]: floor(self / rhs) value.

__mod__

def __mod__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<sub value, #pop.float_literal_bin<mul #pop.float_literal_bin<floordiv value, *"rhs.value`2x">, *"rhs.value`2x">>]

Return the remainder of self divided by rhs.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<sub value, #pop.float_literal_bin<mul #pop.float_literal_bin<floordiv value, *"rhs.value`2x">, *"rhs.value`2x">>]: The remainder of dividing self by rhs.

__radd__

def __radd__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<add *"rhs.value`2x", value>]

Reversed addition operator.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<add *"rhs.value`2x", value>]: The sum of this and the given value.

__rsub__

def __rsub__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<sub *"rhs.value`2x", value>]

Reversed subtraction operator.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<sub *"rhs.value`2x", value>]: The result of subtracting this from the given value.

__rmul__

def __rmul__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<mul *"rhs.value`2x", value>]

Reversed multiplication operator.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<mul *"rhs.value`2x", value>]: The product of the given number and this.

__rtruediv__

def __rtruediv__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<truediv *"rhs.value`2x", value>]

Reversed division.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<truediv *"rhs.value`2x", value>]: The result of dividing the given value by this.

__rfloordiv__

def __rfloordiv__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<floordiv *"rhs.value`2x", value>]

Returns rhs divided by self, rounded down to the nearest integer.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<floordiv *"rhs.value`2x", value>]: floor(rhs / self) value.

__rmod__

def __rmod__(self, rhs: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<sub *"rhs.value`2x", #pop.float_literal_bin<mul #pop.float_literal_bin<floordiv *"rhs.value`2x", value>, value>>]

Return the remainder of rhs divided by self.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<sub *"rhs.value`2x", #pop.float_literal_bin<mul #pop.float_literal_bin<floordiv *"rhs.value`2x", value>, value>>]: The remainder of dividing rhs by self.

is_nan

def is_nan(self) -> Bool

Return whether the FloatLiteral is nan.

Since nan == nan is False, this provides a way to check for nan-ness.

Returns:

Bool: True, if the value is nan, False otherwise.

is_neg_zero

def is_neg_zero(self) -> Bool

Return whether the FloatLiteral is negative zero.

Since FloatLiteral.negative_zero == 0.0 is True, this provides a way to check if the FloatLiteral is negative zero.

Returns:

Bool: True, if the value is negative zero, False otherwise.

__int_literal__

def __int_literal__(self) -> IntLiteral[#pop.float_to_int_literal<value>]

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

Eg. (4.5).__int_literal__() returns 4, and (-3.7).__int_literal__() returns -3.

Returns:

IntLiteral[#pop.float_to_int_literal<value>]: The value as an integer.

__int__

def __int__(self) -> Int

Converts the FloatLiteral value to an Int. If there is a fractional component, then the value is truncated towards zero.

Eg. (4.5).__int__() returns 4, and (-3.7).__int__() returns -3.

Returns:

Int: The value as an integer.

__float__

def __float__(self) -> Float64

Converts the FloatLiteral to a concrete Float64.

Returns:

Float64: The Float value.

write_to

def write_to(self, mut writer: T)

Writes the FloatLiteral in string form.

Args:

  • writer (T): The Writer to write the value to.

write_repr_to

def write_repr_to(self, mut writer: T)

Writes the FloatLiteral in repr form.

Args:

  • writer (T): The Writer to write the value to.

__ceildiv__

def __ceildiv__(self, denominator: FloatLiteral) -> FloatLiteral[#pop.float_literal_bin<mul #pop.float_literal_bin<floordiv value, #pop.float_literal_bin<mul *"denominator.value`2x", #pop.float_literal<-1|1>>>, #pop.float_literal<-1|1>>]

Return the rounded-up result of dividing self by denominator.

Args:

Returns:

FloatLiteral[#pop.float_literal_bin<mul #pop.float_literal_bin<floordiv value, #pop.float_literal_bin<mul *"denominator.value`2x", #pop.float_literal<-1|1>>>, #pop.float_literal<-1|1>>]: The ceiling of dividing numerator by denominator.