Skip to content

Commit 030d324

Browse files
Account for removal of UB in float-to-int casts
This updates the reference per PR rust-lang/rust#71269.
1 parent 892b928 commit 030d324

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: src/expressions/operator-expr.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,11 @@ same trait object.
366366
* zero-extend if the source is unsigned
367367
* sign-extend if the source is signed
368368
* Casting from a float to an integer will round the float towards zero
369-
* **[NOTE: currently this will cause Undefined Behavior if the rounded
370-
value cannot be represented by the target integer type][float-int]**.
371-
This includes Inf and NaN. This is a bug and will be fixed.
369+
* `NaN` will return `0`
370+
* Values larger than the maximum integer value will saturate to the
371+
maximum value of the integer type.
372+
* Values smaller than the minimum integer value will saturate to the
373+
minimum value of the integer type.
372374
* Casting from an integer to float will produce the closest possible float \*
373375
* if necessary, rounding is according to `roundTiesToEven` mode \*\*\*
374376
* on overflow, infinity (of the same sign as the input) is produced
@@ -398,8 +400,6 @@ expected.
398400
number, preferring the one with an even least significant digit if exactly
399401
halfway between two floating point numbers.
400402

401-
[float-int]: https://github.com/rust-lang/rust/issues/10184
402-
403403
## Assignment expressions
404404

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

0 commit comments

Comments
 (0)