divsf3_test.zig (982B) - Raw
1 // Ported from: 2 // 3 // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/divsf3_test.c 4 5 const __divsf3 = @import("divsf3.zig").__divsf3; 6 const testing = @import("std").testing; 7 8 fn compareResultF(result: f32, expected: u32) bool { 9 const rep: u32 = @bitCast(result); 10 11 if (rep == expected) { 12 return true; 13 } 14 // test other possible NaN representation(signal NaN) 15 else if (expected == 0x7fc00000) { 16 if ((rep & 0x7f800000) == 0x7f800000 and 17 (rep & 0x7fffff) > 0) 18 { 19 return true; 20 } 21 } 22 return false; 23 } 24 25 fn test__divsf3(a: f32, b: f32, expected: u32) !void { 26 const x = __divsf3(a, b); 27 const ret = compareResultF(x, expected); 28 try testing.expect(ret == true); 29 } 30 31 test "divsf3" { 32 try test__divsf3(1.0, 3.0, 0x3EAAAAAB); 33 try test__divsf3(2.3509887e-38, 2.0, 0x00800000); 34 try test__divsf3(1.0, 0x1.fffffep-1, 0x3f800001); 35 }