MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

01_numbers/rust/cast.rs:1–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1fn main() {
2 let f = 1.23_f32;
3 let i = f as u8;
4
5 dbg!(i, f);
6
7 let word: u16 = 128;
8 let byte = word as i8;
9 let ubyte = word as u8;
10 dbg!(word, byte, ubyte);
11
12 let too_big = 1000;
13 let too_small = too_big as u8;
14 dbg!(too_big, too_small);
15
16 dbg!(unchecked(0x0fff_ffff, 0x0fff_ffff));
17 dbg!(checked(0x0fff_ffff, 0x0fff_ffff));
18
19 dbg!(float_eq(1.321, 1.32));
20 dbg!(float_eq(1.32, 1.321));
21 dbg!(float_eq(1.320000001, 1.32));
22 dbg!(1.320000001_f32 == 1.32_f32);
23 assert_eq!(1.320000001, 1.32);
24}
25
26/// wraps like it would in C
27pub fn unchecked(x: i32, y: i32) -> i32 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected