You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/literal-expr.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,33 @@ let a: u64 = 123; // type u64
59
59
0usize; // type usize
60
60
```
61
61
62
+
## Floating-point literal expressions
63
+
64
+
A floating-point literal expression consists of a single [FLOAT_LITERAL] token.
65
+
66
+
If the token has a [suffix], the suffix will be the name of one of the [primitive floating-point types][floating-point types]: `f32` or `f64`, and the expression has that type.
67
+
68
+
If the token has no suffix, the expression's type is determined by type inference:
69
+
70
+
* If a floating-point type can be _uniquely_ determined from the surrounding program context, the expression has that type.
71
+
72
+
* If the program context under-constrains the type, it defaults to `f64`.
73
+
74
+
* If the program context over-constrains the type, it is considered a static type error.
Copy file name to clipboardExpand all lines: src/tokens.md
+9-25Lines changed: 9 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -465,40 +465,24 @@ A _floating-point literal_ has one of two forms:
465
465
466
466
Like integer literals, a floating-point literal may be followed by a
467
467
suffix, so long as the pre-suffix part does not end with `U+002E` (`.`).
468
-
The suffix forcibly sets the type of the literal. There are two valid
469
-
_floating-point suffixes_, `f32` and `f64` (the 32-bit and 64-bit floating point
470
-
types), which explicitly determine the type of the literal.
471
-
472
-
The type of an _unsuffixed_ floating-point literal is determined by
473
-
type inference:
474
-
475
-
* If a floating-point type can be _uniquely_ determined from the
476
-
surrounding program context, the unsuffixed floating-point literal
477
-
has that type.
478
-
479
-
* If the program context under-constrains the type, it defaults to `f64`.
480
-
481
-
* If the program context over-constrains the type, it is considered a
482
-
static type error.
468
+
There are two valid _floating-point suffixes_: `f32` and `f64` (the names of the 32-bit and 64-bit [primitive floating-point types][floating-point types]).
469
+
See [literal expressions] for the effect of these suffixes.
483
470
484
471
Examples of floating-point literals of various forms:
485
472
486
473
```rust
487
-
123.0f64;// type f64
488
-
0.1f64;// type f64
489
-
0.1f32;// type f32
490
-
12E+99_f64;// type f64
491
-
5f32;// type f32
492
-
letx:f64=2.;// type f64
474
+
123.0f64;
475
+
0.1f64;
476
+
0.1f32;
477
+
12E+99_f64;
478
+
5f32;
479
+
letx:f64=2.;
493
480
```
494
481
495
482
This last example is different because it is not possible to use the suffix
496
483
syntax with a floating point literal ending in a period. `2.f64` would attempt
497
484
to call a method named `f64` on `2`.
498
485
499
-
The representation semantics of floating-point numbers are described in
500
-
["Machine Types"][machine types].
501
-
502
486
### Boolean literals
503
487
504
488
> **<sup>Lexer</sup>**\
@@ -642,6 +626,7 @@ Similarly the `r`, `b`, and `br` prefixes used in raw string literals, byte lite
0 commit comments