diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-05-06 19:22:40 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-05-06 22:41:00 -0700 |
| commit | ec95e00e28cb23f37dc097f71afd7090e947a1cd (patch) | |
| tree | a7393f13c3d2c7895eb3687d0ebd7f3205699289 /lib/compiler_rt/comparedf2_test.zig | |
| parent | 3b60ab4872355f0b9a9c7d0794ca8b548ab99412 (diff) | |
| download | zig-ec95e00e28cb23f37dc097f71afd7090e947a1cd.tar.gz zig-ec95e00e28cb23f37dc097f71afd7090e947a1cd.zip | |
flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.
* stage2: fix cleanup bug when creating Module
* flatten lib/std/special/* to lib/*
- this was motivated by making main_pkg_is_inside_std false for
compiler_rt & friends.
* rename "mini libc" to "universal libc"
Diffstat (limited to 'lib/compiler_rt/comparedf2_test.zig')
| -rw-r--r-- | lib/compiler_rt/comparedf2_test.zig | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/lib/compiler_rt/comparedf2_test.zig b/lib/compiler_rt/comparedf2_test.zig new file mode 100644 index 0000000000..a80297ffbf --- /dev/null +++ b/lib/compiler_rt/comparedf2_test.zig @@ -0,0 +1,101 @@ +// Ported from: +// +// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/comparedf2_test.c + +const std = @import("std"); +const builtin = @import("builtin"); +const is_test = builtin.is_test; + +const comparedf2 = @import("compareXf2.zig"); + +const TestVector = struct { + a: f64, + b: f64, + eqReference: c_int, + geReference: c_int, + gtReference: c_int, + leReference: c_int, + ltReference: c_int, + neReference: c_int, + unReference: c_int, +}; + +fn test__cmpdf2(vector: TestVector) bool { + if (comparedf2.__eqdf2(vector.a, vector.b) != vector.eqReference) { + return false; + } + if (comparedf2.__gedf2(vector.a, vector.b) != vector.geReference) { + return false; + } + if (comparedf2.__gtdf2(vector.a, vector.b) != vector.gtReference) { + return false; + } + if (comparedf2.__ledf2(vector.a, vector.b) != vector.leReference) { + return false; + } + if (comparedf2.__ltdf2(vector.a, vector.b) != vector.ltReference) { + return false; + } + if (comparedf2.__nedf2(vector.a, vector.b) != vector.neReference) { + return false; + } + if (comparedf2.__unorddf2(vector.a, vector.b) != vector.unReference) { + return false; + } + return true; +} + +const arguments = [_]f64{ + std.math.nan(f64), + -std.math.inf(f64), + -0x1.fffffffffffffp1023, + -0x1.0000000000001p0 - 0x1.0000000000000p0, + -0x1.fffffffffffffp-1, + -0x1.0000000000000p-1022, + -0x0.fffffffffffffp-1022, + -0x0.0000000000001p-1022, + -0.0, + 0.0, + 0x0.0000000000001p-1022, + 0x0.fffffffffffffp-1022, + 0x1.0000000000000p-1022, + 0x1.fffffffffffffp-1, + 0x1.0000000000000p0, + 0x1.0000000000001p0, + 0x1.fffffffffffffp1023, + std.math.inf(f64), +}; + +fn generateVector(comptime a: f64, comptime b: f64) TestVector { + const leResult = if (a < b) -1 else if (a == b) 0 else 1; + const geResult = if (a > b) 1 else if (a == b) 0 else -1; + const unResult = if (a != a or b != b) 1 else 0; + return TestVector{ + .a = a, + .b = b, + .eqReference = leResult, + .geReference = geResult, + .gtReference = geResult, + .leReference = leResult, + .ltReference = leResult, + .neReference = leResult, + .unReference = unResult, + }; +} + +const test_vectors = init: { + @setEvalBranchQuota(10000); + var vectors: [arguments.len * arguments.len]TestVector = undefined; + for (arguments[0..]) |arg_i, i| { + for (arguments[0..]) |arg_j, j| { + vectors[(i * arguments.len) + j] = generateVector(arg_i, arg_j); + } + } + break :init vectors; +}; + +test "compare f64" { + for (test_vectors) |vector| { + try std.testing.expect(test__cmpdf2(vector)); + } +} |
