diff options
| author | Diggory Hardy <github@dhardy.name> | 2015-04-27 12:24:47 +0100 |
|---|---|---|
| committer | Diggory Hardy <github@dhardy.name> | 2015-04-27 12:24:47 +0100 |
| commit | cf650a217495940bdf3f8a843f5dd959b6e37b5e (patch) | |
| tree | c1a54c5c74705a108c2e9cd200886ba8f35b49e5 /src/doc/reference.md | |
| parent | 709f3c51302ca86617cca4a67648302c5088381c (diff) | |
| download | rust-cf650a217495940bdf3f8a843f5dd959b6e37b5e.tar.gz rust-cf650a217495940bdf3f8a843f5dd959b6e37b5e.zip | |
Update reference.md: floating-point section
Clarify type inference of floating-point literals
Diffstat (limited to 'src/doc/reference.md')
| -rw-r--r-- | src/doc/reference.md | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md index a7ed05c5a23..848c0df10ee 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -366,11 +366,19 @@ A _floating-point literal_ has one of two forms: optionally followed by another decimal literal, with an optional _exponent_. * A single _decimal literal_ followed by an _exponent_. -By default, a floating-point literal has a generic type, and, like integer -literals, the type must be uniquely determined from the context. There are two valid +Like integer literals, a floating-point literal may be followed by a +suffix, so long as the pre-suffix part does not end with `U+002E` (`.`). +The suffix forcibly sets the type of the literal. There are two valid _floating-point suffixes_, `f32` and `f64` (the 32-bit and 64-bit floating point types), which explicitly determine the type of the literal. +The type of an _unsuffixed_ floating-point literal is determined by type +inference. If a floating-point type can be _uniquely_ determined from the +surrounding program context, the unsuffixed floating-point literal has that type. +If the program context underconstrains the type, it defaults to double-precision `f64`; +if the program context overconstrains the type, it is considered a static type +error. + Examples of floating-point literals of various forms: ``` |
