Skip to content

Commit c2ffc21

Browse files
authored
Merge pull request #232 from turtleslow/saturating-cast-patch-1
Update casts.md
2 parents 8641e70 + 5b26dfb commit c2ffc21

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/casts.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,14 @@ For numeric casts, there are quite a few cases to consider:
5151
* casting from a smaller integer to a larger integer (e.g. u8 -> u32) will
5252
* zero-extend if the source is unsigned
5353
* sign-extend if the source is signed
54-
* casting from a float to an integer will round the float towards zero
55-
* **[NOTE: currently this will cause Undefined Behavior if the rounded
56-
value cannot be represented by the target integer type][float-int]**.
57-
This includes Inf and NaN. This is a bug and will be fixed.
54+
* casting from a float to an integer will round the float towards zero and
55+
produces a "saturating cast" when the float is outside the integer's range
56+
* floats that are too big turn into the largest possible integer
57+
* floats that are too small produce the smallest possible integer
58+
* NaN produces zero
5859
* casting from an integer to float will produce the floating point
5960
representation of the integer, rounded if necessary (rounding to
6061
nearest, ties to even)
6162
* casting from an f32 to an f64 is perfect and lossless
6263
* casting from an f64 to an f32 will produce the closest possible value
6364
(rounding to nearest, ties to even)
64-
65-
66-
[float-int]: https://github.com/rust-lang/rust/issues/10184

0 commit comments

Comments
 (0)