Skip to content

reference: improve readability of type inference explanations for flo… #26785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,16 @@ type of the literal. The integer suffix must be the name of one of the
integral types: `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`,
`isize`, or `usize`.

The type of an _unsuffixed_ integer literal is determined by type inference.
If an integer type can be _uniquely_ determined from the surrounding program
context, the unsuffixed integer literal has that type. If the program context
underconstrains the type, it defaults to the signed 32-bit integer `i32`; if
the program context overconstrains the type, it is considered a static type
error.
The type of an _unsuffixed_ integer literal is determined by type inference:

* If an integer type can be _uniquely_ determined from the surrounding
program context, the unsuffixed integer literal has that type.

* If the program context underconstrains the type, it defaults to the
signed 32-bit integer `i32`.

* If the program context overconstrains the type, it is considered a
static type error.

Examples of integer literals of various forms:

Expand Down Expand Up @@ -371,12 +375,17 @@ 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.
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 `f64`.

* If the program context overconstrains the type, it is considered a
static type error.

Examples of floating-point literals of various forms:

Expand Down