File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 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:
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
You can’t perform that action at this time.
0 commit comments