Skip to content

Commit cf650a2

Browse files
committed
Update reference.md: floating-point section
Clarify type inference of floating-point literals
1 parent 709f3c5 commit cf650a2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/doc/reference.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,19 @@ A _floating-point literal_ has one of two forms:
366366
optionally followed by another decimal literal, with an optional _exponent_.
367367
* A single _decimal literal_ followed by an _exponent_.
368368

369-
By default, a floating-point literal has a generic type, and, like integer
370-
literals, the type must be uniquely determined from the context. There are two valid
369+
Like integer literals, a floating-point literal may be followed by a
370+
suffix, so long as the pre-suffix part does not end with `U+002E` (`.`).
371+
The suffix forcibly sets the type of the literal. There are two valid
371372
_floating-point suffixes_, `f32` and `f64` (the 32-bit and 64-bit floating point
372373
types), which explicitly determine the type of the literal.
373374

375+
The type of an _unsuffixed_ floating-point literal is determined by type
376+
inference. If a floating-point type can be _uniquely_ determined from the
377+
surrounding program context, the unsuffixed floating-point literal has that type.
378+
If the program context underconstrains the type, it defaults to double-precision `f64`;
379+
if the program context overconstrains the type, it is considered a static type
380+
error.
381+
374382
Examples of floating-point literals of various forms:
375383

376384
```

0 commit comments

Comments
 (0)