divdf3_test.zig (1051B) - Raw
1 // Ported from: 2 // 3 // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/divdf3_test.c 4 5 const __divdf3 = @import("divdf3.zig").__divdf3; 6 const testing = @import("std").testing; 7 8 fn compareResultD(result: f64, expected: u64) bool { 9 const rep: u64 = @bitCast(result); 10 11 if (rep == expected) { 12 return true; 13 } 14 // test other possible NaN representation(signal NaN) 15 else if (expected == 0x7ff8000000000000) { 16 if ((rep & 0x7ff0000000000000) == 0x7ff0000000000000 and 17 (rep & 0xfffffffffffff) > 0) 18 { 19 return true; 20 } 21 } 22 return false; 23 } 24 25 fn test__divdf3(a: f64, b: f64, expected: u64) !void { 26 const x = __divdf3(a, b); 27 const ret = compareResultD(x, expected); 28 try testing.expect(ret == true); 29 } 30 31 test "divdf3" { 32 try test__divdf3(1.0, 3.0, 0x3fd5555555555555); 33 try test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000); 34 try test__divdf3(1.0, 0x1.fffffffffffffp-1, 0x3ff0000000000001); 35 }