You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/types/cast.md
+9-4Lines changed: 9 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,8 @@ fn main() {
22
22
let integer = decimal as u8;
23
23
let character = integer as char;
24
24
25
-
// Error! There are limitations in conversion rules. A float cannot be directly converted to a char.
25
+
// Error! There are limitations in conversion rules.
26
+
// A float cannot be directly converted to a char.
26
27
let character = decimal as char;
27
28
// FIXME ^ Comment out this line
28
29
@@ -60,8 +61,10 @@ fn main() {
60
61
// and the two's complement of 232 is -24
61
62
println!(" 232 as a i8 is : {}", 232 as i8);
62
63
63
-
// Since Rust 1.45, the `as` keyword performs a *saturating cast* when casting from float to int.
64
-
// If the floating point value exceeds the upper bound or is less than the lower bound, the returned value will be equal to the bound crossed.
64
+
// Since Rust 1.45, the `as` keyword performs a *saturating cast*
65
+
// when casting from float to int. If the floating point value exceeds
66
+
// the upper bound or is less than the lower bound, the returned value
67
+
// will be equal to the bound crossed.
65
68
66
69
// 300.0 is 255
67
70
println!("300.0 is {}", 300.0_f32 as u8);
@@ -70,7 +73,9 @@ fn main() {
70
73
// nan as u8 is 0
71
74
println!("nan as u8 is {}", f32::NAN as u8);
72
75
73
-
// This behavior incurs a small runtime cost and can be avoided with unsafe methods, however the results might overflow and return **unsound values**. Use these methods wisely:
76
+
// This behavior incurs a small runtime cost and can be avoided
77
+
// with unsafe methods, however the results might overflow and
78
+
// return **unsound values**. Use these methods wisely:
74
79
unsafe {
75
80
// 300.0 is 44
76
81
println!("300.0 is {}", 300.0_f32.to_int_unchecked::<u8>());
0 commit comments