1// Ported from:
2//
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/comparesf2_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_f32 = impl.cmp_f32;
13const unord_f32 = impl.unord_f32;
14
15const arguments = [_]f32{
16 std.math.nan(f32),
17 -std.math.inf(f32),
18 -0x1.fffffep127,
19 -0x1.000002p0 - 0x1.000000p0,
20 -0x1.fffffep-1,
21 -0x1.000000p-126,
22 -0x0.fffffep-126,
23 -0x0.000002p-126,
24 -0.0,
25 0.0,
26 0x0.000002p-126,
27 0x0.fffffep-126,
28 0x1.000000p-126,
29 0x1.fffffep-1,
30 0x1.000000p0,
31 0x1.000002p0,
32 0x1.fffffep127,
33 std.math.inf(f32),
34};
35
36test "compare f32" {
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 i - @intFromBool(i >= 9),
42 j - @intFromBool(j >= 9),
43 )) {
44 .lt => .lt,
45 .eq => .eq,
46 .gt => .gt,
47 };
48 try std.testing.expect(expected_order == cmp_f32(arg_i, arg_j));
49 try std.testing.expect(expected_unord == unord_f32(arg_i, arg_j));
50 }
51 }
52}