nx_f32_cvt_test.nx source
↩ module page · 61 lines · 2466 B
1// nx_f32_cvt_test.nx -- smoke for nx_f32_cvt.nx.
2
3import "nx_syscalls.nx"
4import "nx_tier.nx"
5import "nx_f16.nx"
6import "nx_f32.nx"
7import "nx_f32_cvt.nx"
8
9func main() -> i64 {
10 // ===== f16 -> f32 (canonical patterns) =====
11 // f16 1.0 = 0x3C00; f32 1.0 = 0x3F800000
12 if nx_f16_to_f32(0x3C00) != 0x3F800000 { return 10 }
13 // f16 2.0 = 0x4000; f32 2.0 = 0x40000000
14 if nx_f16_to_f32(0x4000) != 0x40000000 { return 11 }
15 // f16 0.5 = 0x3800; f32 0.5 = 0x3F000000
16 if nx_f16_to_f32(0x3800) != 0x3F000000 { return 12 }
17 // f16 +0 = 0x0000; f32 +0 = 0
18 if nx_f16_to_f32(0x0000) != 0x00000000 { return 13 }
19 // f16 +inf = 0x7C00; f32 +inf = 0x7F800000
20 if nx_f16_to_f32(0x7C00) != 0x7F800000 { return 14 }
21 // f16 4.0 = 0x4400; f32 4.0 = 0x40800000
22 if nx_f16_to_f32(0x4400) != 0x40800000 { return 15 }
23 // f16 1.5 = 0x3E00; f32 1.5 = 0x3FC00000
24 if nx_f16_to_f32(0x3E00) != 0x3FC00000 { return 16 }
25
26 // ===== i32 -> f32 (small ints, all exact) =====
27 if nx_i32_to_f32(0) != 0 { return 30 }
28 if nx_i32_to_f32(1) != 0x3F800000 { return 31 } // 1.0
29 if nx_i32_to_f32(2) != 0x40000000 { return 32 } // 2.0
30 if nx_i32_to_f32(3) != 0x40400000 { return 33 } // 3.0
31 if nx_i32_to_f32(4) != 0x40800000 { return 34 } // 4.0
32 if nx_i32_to_f32(15) != 0x41700000 { return 35 } // 15.0
33 if nx_i32_to_f32(63) != 0x427C0000 { return 36 } // 63.0
34 if nx_i32_to_f32(16) != 0x41800000 { return 37 } // 16.0
35 // Powers of 2
36 if nx_i32_to_f32(256) != 0x43800000 { return 40 } // 256.0
37 if nx_i32_to_f32(1024) != 0x44800000 { return 41 } // 1024.0
38 if nx_i32_to_f32(16384) != 0x46800000 { return 42 } // 16384.0
39
40 // ===== Q10 -> f32 =====
41 // Q10 1024 = 1.0 -> 0x3F800000
42 if nx_q10_to_f32(1024) != 0x3F800000 { return 60 }
43 // Q10 2048 = 2.0 -> 0x40000000
44 if nx_q10_to_f32(2048) != 0x40000000 { return 61 }
45 // Q10 512 = 0.5 -> 0x3F000000
46 if nx_q10_to_f32(512) != 0x3F000000 { return 62 }
47 // Q10 0 = 0
48 if nx_q10_to_f32(0) != 0 { return 63 }
49
50 // ===== Q14 -> f32 =====
51 // Q14 16384 = 1.0 -> 0x3F800000
52 if nx_q14_to_f32(16384) != 0x3F800000 { return 80 }
53 // Q14 32768 = 2.0 -> 0x40000000
54 if nx_q14_to_f32(32768) != 0x40000000 { return 81 }
55 // Q14 8192 = 0.5 -> 0x3F000000
56 if nx_q14_to_f32(8192) != 0x3F000000 { return 82 }
57 // Q14 0 = 0
58 if nx_q14_to_f32(0) != 0 { return 83 }
59
60 return 0
61}