Mojo struct
FloatLiteral
@register_passable(trivial)
struct FloatLiteral[value: !pop.float_literal]
Mojo floating point literal type.
Parameters
- value (
!pop.float_literal
): The underlying infinite precision floating point value.
Aliases
nan
:infinity = inf
:negative_infinity = -inf
:negative_zero = -0.0
:
Implemented traits
AnyType
,
Boolable
,
CollectionElement
,
Copyable
,
ExplicitlyCopyable
,
Floatable
,
ImplicitlyBoolable
,
Intable
,
Movable
,
Stringable
,
UnknownDestructibility
Methods
__init__
__init__() -> Self
Create a FloatLiteral for any parameter value.
@implicit
__init__(value: IntLiteral[value]) -> FloatLiteral[#pop.int_to_float_literal<value>]
Convert an IntLiteral to a FloatLiteral value.
Args:
- value (
IntLiteral[value]
): The IntLiteral value.
__bool__
__bool__(self) -> Bool
A FloatLiteral value is true if it is non-zero.
Returns:
True if non-zero.
__neg__
__neg__(self) -> FloatLiteral[#pop.float_literal_bin< mul value, #pop.float_literal<-1|1>>]
Return the negation of the FloatLiteral value.
Returns:
The negated FloatLiteral value.
__lt__
__lt__(self, rhs: FloatLiteral[value]) -> Bool
Less than comparison.
Args:
- rhs (
FloatLiteral[value]
): The value to compare.
Returns:
True if this value is less than rhs
.
__le__
__le__(self, rhs: FloatLiteral[value]) -> Bool
Less than or equal to comparison.
Args:
- rhs (
FloatLiteral[value]
): The value to compare.
Returns:
True if this value is less than or equal to rhs
.
__eq__
__eq__(self, rhs: FloatLiteral[value]) -> Bool
Compare for equality.
Args:
- rhs (
FloatLiteral[value]
): The value to compare.
Returns:
True if they are equal.
__ne__
__ne__(self, rhs: FloatLiteral[value]) -> Bool
Compare for inequality.
Args:
- rhs (
FloatLiteral[value]
): The value to compare.
Returns:
True if they are not equal.
__gt__
__gt__(self, rhs: FloatLiteral[value]) -> Bool
Greater than comparison.
Args:
- rhs (
FloatLiteral[value]
): The value to compare.
Returns:
True if this value is greater than rhs
.
__ge__
__ge__(self, rhs: FloatLiteral[value]) -> Bool
Greater than or equal to comparison.
Args:
- rhs (
FloatLiteral[value]
): The value to compare.
Returns:
True if this value is greater than or equal to rhs
.
__add__
__add__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< add value, value>]
Add two FloatLiterals.
Args:
- rhs (
FloatLiteral[value]
): The value to add.
Returns:
The sum of the two values.
__sub__
__sub__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< sub value, value>]
Subtract two FloatLiterals.
Args:
- rhs (
FloatLiteral[value]
): The value to subtract.
Returns:
The difference of the two values.
__mul__
__mul__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< mul value, value>]
Multiply two FloatLiterals.
Args:
- rhs (
FloatLiteral[value]
): The value to multiply.
Returns:
The product of the two values.
__truediv__
__truediv__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< truediv value, value>]
Divide two FloatLiterals.
Args:
- rhs (
FloatLiteral[value]
): The value to divide.
Returns:
The quotient of the two values.
__floordiv__
__floordiv__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< floordiv value, value>]
Returns self divided by rhs, rounded down to the nearest integer.
Args:
- rhs (
FloatLiteral[value]
): The divisor value.
Returns:
floor(self / rhs)
value.
__mod__
__mod__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< sub value, #pop.float_literal_bin< mul #pop.float_literal_bin< floordiv value, value>, value>>]
Return the remainder of self divided by rhs.
Args:
- rhs (
FloatLiteral[value]
): The value to divide on.
Returns:
The remainder of dividing self by rhs.
__radd__
__radd__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< add value, value>]
Reversed addition operator.
Args:
- rhs (
FloatLiteral[value]
): The value to add.
Returns:
The sum of this and the given value.
__rsub__
__rsub__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< sub value, value>]
Reversed subtraction operator.
Args:
- rhs (
FloatLiteral[value]
): The value to subtract from.
Returns:
The result of subtracting this from the given value.
__rmul__
__rmul__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< mul value, value>]
Reversed multiplication operator.
Args:
- rhs (
FloatLiteral[value]
): The value to multiply.
Returns:
The product of the given number and this.
__rtruediv__
__rtruediv__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< truediv value, value>]
Reversed division.
Args:
- rhs (
FloatLiteral[value]
): The value to be divided by this.
Returns:
The result of dividing the given value by this.
__rfloordiv__
__rfloordiv__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< floordiv value, value>]
Returns rhs divided by self, rounded down to the nearest integer.
Args:
- rhs (
FloatLiteral[value]
): The value to be divided by self.
Returns:
floor(rhs / self)
value.
__rmod__
__rmod__(self, rhs: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< sub value, #pop.float_literal_bin< mul #pop.float_literal_bin< floordiv value, value>, value>>]
Return the remainder of rhs divided by self.
Args:
- rhs (
FloatLiteral[value]
): The value to divide on.
Returns:
The remainder of dividing rhs by self.
is_nan
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:
True, if the value is nan, False otherwise.
is_neg_zero
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:
True, if the value is negative zero, False otherwise.
__str__
__str__(self) -> String
Get the float as a string.
Returns:
A string representation.
__int_literal__
__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:
The value as an integer.
__int__
__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:
The value as an integer.
__float__
__float__(self) -> SIMD[float64, 1]
Converts the FloatLiteral to a concrete Float64.
Returns:
The Float value.
__as_bool__
__as_bool__(self) -> Bool
A FloatLiteral value is true if it is non-zero.
Returns:
True if non-zero.
__ceildiv__
__ceildiv__(self, denominator: FloatLiteral[value]) -> FloatLiteral[#pop.float_literal_bin< mul #pop.float_literal_bin< floordiv value, #pop.float_literal_bin< mul value, #pop.float_literal<-1|1>>>, #pop.float_literal<-1|1>>]
Return the rounded-up result of dividing self by denominator.
Args:
- denominator (
FloatLiteral[value]
): The denominator.
Returns:
The ceiling of dividing numerator by denominator.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!