Mojo struct
FloatLiteral
Mojo floating point literal type.
Aliasesβ
fp_type = !kgen.float_literal
:nan = #kgen.float_literal<nan>
:infinity = #kgen.float_literal<inf>
:negative_infinity = #kgen.float_literal<neg_inf>
:negative_zero = #kgen.float_literal<neg_zero>
:
Fieldsβ
- βvalue (
!kgen.float_literal
): The underlying storage for the floating point value.
Implemented traitsβ
Absable
,
AnyType
,
Boolable
,
CeilDivable
,
Ceilable
,
Comparable
,
Copyable
,
EqualityComparable
,
Floorable
,
ImplicitlyBoolable
,
Intable
,
Movable
,
Roundable
,
Stringable
,
Truncable
Methodsβ
__init__
β
__init__(inout self: Self, value: !kgen.float_literal)
Create a FloatLiteral value from a kgen.float_literal value.
Args:
- βvalue (
!kgen.float_literal
): The float value.
__init__(inout self: Self, value: IntLiteral)
Convert an IntLiteral to a FloatLiteral value.
Args:
- βvalue (
IntLiteral
): The IntLiteral value.
__bool__
β
__bool__(self: Self) -> Bool
A FloatLiteral value is true if it is non-zero.
Returns:
True if non-zero.
__neg__
β
__neg__(self: Self) -> Self
Return the negation of the FloatLiteral value.
Returns:
The negated FloatLiteral 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 FloatLiterals.
Args:
- βrhs (
Self
): The value to add.
Returns:
The sum of the two values.
__sub__
β
__sub__(self: Self, rhs: Self) -> Self
Subtract two FloatLiterals.
Args:
- βrhs (
Self
): The value to subtract.
Returns:
The difference of the two values.
__mul__
β
__mul__(self: Self, rhs: Self) -> Self
Multiply two FloatLiterals.
Args:
- βrhs (
Self
): The value to multiply.
Returns:
The product of the two values.
__truediv__
β
__truediv__(self: Self, rhs: Self) -> Self
Divide two FloatLiterals.
Args:
- βrhs (
Self
): The value to divide.
Returns:
The quotient of the two values.
__floordiv__
β
__floordiv__(self: Self, rhs: Self) -> Self
Returns self divided by rhs, rounded down to the nearest integer.
Args:
- βrhs (
Self
): The divisor value.
Returns:
floor(self / rhs)
value.
__mod__
β
__mod__(self: Self, rhs: Self) -> Self
Return the remainder of self divided by rhs.
Args:
- βrhs (
Self
): The value to divide on.
Returns:
The remainder of dividing self by rhs.
__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
Returns rhs divided by self, rounded down to the nearest integer.
Args:
- βrhs (
Self
): The value to be divided by self.
Returns:
floor(rhs / self)
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.
is_nan
β
is_nan(self: 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: 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: Self) -> String
Get the float as a string.
Returns:
A string representation.
__int_literal__
β
__int_literal__(self: Self) -> IntLiteral
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: 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.
__as_bool__
β
__as_bool__(self: Self) -> Bool
A FloatLiteral value is true if it is non-zero.
Returns:
True if non-zero.
__abs__
β
__abs__(self: Self) -> Self
Return the absolute value of the FloatLiteral.
Returns:
The absolute value.
__floor__
β
__floor__(self: Self) -> Self
Return the floor value of the FloatLiteral.
Returns:
The floor value.
__ceil__
β
__ceil__(self: Self) -> Self
Return the ceiling value of the FloatLiteral.
Returns:
The ceiling value.
__trunc__
β
__trunc__(self: Self) -> Self
Truncates the floating point literal. If there is a fractional component, then the value is truncated towards zero.
For example, (4.5).__trunc__()
returns 4.0
, and (-3.7).__trunc__()
returns -3.0
.
Returns:
The truncated FloatLiteral value.
__round__
β
__round__(self: Self) -> Self
Return the rounded value of the FloatLiteral.
Returns:
The rounded value.
__round__(self: Self, ndigits: Int) -> Self
Return the rounded value of the FloatLiteral.
Args:
- βndigits (
Int
): The number of digits to round to. Defaults to 0.
Returns:
The rounded value.
__divmod__
β
__divmod__(self: Self, rhs: Self) -> Tuple[FloatLiteral, FloatLiteral]
Return a tuple with the quotient and the remainder of self divided by rhs.
Args:
- βrhs (
Self
): The value to divide on.
Returns:
A tuple with the dividend and the remainder.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?