Skip to content

Commit c8b9a20

Browse files
committed
Literal expressions: add a Note on infinite and NaN floating-point literals
1 parent 72a554a commit c8b9a20

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/expressions/literal-expr.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ The value of the expression is determined from the string representation of the
108108

109109
* The string is converted to the expression's type as if by [`f32::from_str`] or [`f64::from_str`].
110110

111+
> **Note**: `inf` and `NaN` are not literal tokens.
112+
> The [`f32::INFINITY`], [`f64::INFINITY`], [`f32::NAN`], and [`f64::NAN`] constants can be used instead of literal expressions.
113+
> A literal large enough to be evaluated as infinite will trigger the `overflowing_literals` lint check.
114+
111115
[constant expression]: ../const_eval.md#constant-expressions
112116
[floating-point types]: ../types/numeric.md#floating-point-types
113117
[lint check]: ../attributes/diagnostics.md#lint-check-attributes
@@ -116,7 +120,11 @@ The value of the expression is determined from the string representation of the
116120
[numeric types]: ../types/numeric.md
117121
[suffix]: ../tokens.md#suffixes
118122
[`f32::from_str`]: ../../core/primitive.f32.md#method.from_str
123+
[`f32::INFINITY`]: ../../core/primitive.f32.md#associatedconstant.INFINITY
124+
[`f32::NAN`]: ../../core/primitive.f32.md#associatedconstant.NAN
119125
[`f64::from_str`]: ../../core/primitive.f64.md#method.from_str
126+
[`f64::INFINITY`]: ../../core/primitive.f64.md#associatedconstant.INFINITY
127+
[`f64::NAN`]: ../../core/primitive.f64.md#associatedconstant.NAN
120128
[`u128::from_str_radix`]: ../../core/primitive.u128.md#method.from_str_radix
121129
[CHAR_LITERAL]: ../tokens.md#character-literals
122130
[STRING_LITERAL]: ../tokens.md#string-literals

0 commit comments

Comments
 (0)