Skip to content
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

Account for removal of UB in float-to-int casts #810

Merged
merged 1 commit into from
May 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/expressions/operator-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,11 @@ same trait object.
* zero-extend if the source is unsigned
* sign-extend if the source is signed
* Casting from a float to an integer will round the float towards zero
* **[NOTE: currently this will cause Undefined Behavior if the rounded
value cannot be represented by the target integer type][float-int]**.
This includes Inf and NaN. This is a bug and will be fixed.
* `NaN` will return `0`
* Values larger than the maximum integer value will saturate to the
maximum value of the integer type.
* Values smaller than the minimum integer value will saturate to the
minimum value of the integer type.
* Casting from an integer to float will produce the closest possible float \*
* if necessary, rounding is according to `roundTiesToEven` mode \*\*\*
* on overflow, infinity (of the same sign as the input) is produced
Expand Down Expand Up @@ -398,8 +400,6 @@ expected.
number, preferring the one with an even least significant digit if exactly
halfway between two floating point numbers.

[float-int]: https://github.com/rust-lang/rust/issues/10184

## Assignment expressions

> **<sup>Syntax</sup>**\
Expand Down Expand Up @@ -456,7 +456,6 @@ assert_eq!(x, 14);
[place expression]: ../expressions.md#place-expressions-and-value-expressions
[value expression]: ../expressions.md#place-expressions-and-value-expressions
[temporary value]: ../expressions.md#temporaries
[float-int]: https://github.com/rust-lang/rust/issues/10184
[float-float]: https://github.com/rust-lang/rust/issues/15536
[`unit` type]: ../types/tuple.md

Expand Down