File tree 1 file changed +5
-7
lines changed 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -51,16 +51,14 @@ For numeric casts, there are quite a few cases to consider:
51
51
* casting from a smaller integer to a larger integer (e.g. u8 -> u32) will
52
52
* zero-extend if the source is unsigned
53
53
* 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
58
59
* casting from an integer to float will produce the floating point
59
60
representation of the integer, rounded if necessary (rounding to
60
61
nearest, ties to even)
61
62
* casting from an f32 to an f64 is perfect and lossless
62
63
* casting from an f64 to an f32 will produce the closest possible value
63
64
(rounding to nearest, ties to even)
64
-
65
-
66
- [ float-int ] : https://github.com/rust-lang/rust/issues/10184
You can’t perform that action at this time.
0 commit comments