1// Ported from:
2//
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/comparedf2_test.c
4
5const std = @import("std");
6const builtin = @import("builtin");
7
8const compiler_rt = @import("../compiler_rt.zig");
9
10const impl = @import("comparef.zig");
11const Order = impl.Order;
12const cmp_f64 = impl.cmp_f64;
13const unord_f64 = impl.unord_f64;
14
15const arguments = [_]f64{
16 std.math.nan(f64),
17 -std.math.inf(f64),
18 -0x1.fffffffffffffp1023,
19 -0x1.0000000000001p0 - 0x1.0000000000000p0,
20 -0x1.fffffffffffffp-1,
21 -0x1.0000000000000p-1022,
22 -0x0.fffffffffffffp-1022,
23 -0x0.0000000000001p-1022,
24 -0.0,
25 0.0,
26 0x0.0000000000001p-1022,
27 0x0.fffffffffffffp-1022,
28 0x1.0000000000000p-1022,
29 0x1.fffffffffffffp-1,
30 0x1.0000000000000p0,
31 0x1.0000000000001p0,
32 0x1.fffffffffffffp1023,
33 std.math.inf(f64),
34};
35
36test "compare f64" {
37 for (arguments[0..], 0..) |arg_i, i| {
38 for (arguments[0..], 0..) |arg_j, j| {
39 const expected_unord = i == 0 or j == 0;
40 const expected_order: ?Order = if (expected_unord) null else switch (std.math.order(
41 if (i >= 9) i - 1 else i,
42 if (j >= 9) j - 1 else j,
43 )) {
44 .lt => .lt,
45 .eq => .eq,
46 .gt => .gt,
47 };
48 try std.testing.expect(expected_order == cmp_f64(arg_i, arg_j));
49 try std.testing.expect(expected_unord == unord_f64(arg_i, arg_j));
50 }
51 }
52}