master
1///! The quoted behavior definitions are from
2///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines
3const common = @import("./common.zig");
4const comparef = @import("./comparef.zig");
5
6pub const panic = common.panic;
7
8comptime {
9 @export(&__eqxf2, .{ .name = "__eqxf2", .linkage = common.linkage, .visibility = common.visibility });
10 @export(&__nexf2, .{ .name = "__nexf2", .linkage = common.linkage, .visibility = common.visibility });
11 @export(&__lexf2, .{ .name = "__lexf2", .linkage = common.linkage, .visibility = common.visibility });
12 @export(&__cmpxf2, .{ .name = "__cmpxf2", .linkage = common.linkage, .visibility = common.visibility });
13 @export(&__ltxf2, .{ .name = "__ltxf2", .linkage = common.linkage, .visibility = common.visibility });
14}
15
16/// "These functions calculate a <=> b. That is, if a is less than b, they return -1;
17/// if a is greater than b, they return 1; and if a and b are equal they return 0.
18/// If either argument is NaN they return 1..."
19///
20/// Note that this matches the definition of `__lexf2`, `__eqxf2`, `__nexf2`, `__cmpxf2`,
21/// and `__ltxf2`.
22fn __cmpxf2(a: f80, b: f80) callconv(.c) i32 {
23 return @intFromEnum(comparef.cmp_f80(comparef.LE, a, b));
24}
25
26/// "These functions return a value less than or equal to zero if neither argument is NaN,
27/// and a is less than or equal to b."
28fn __lexf2(a: f80, b: f80) callconv(.c) i32 {
29 return __cmpxf2(a, b);
30}
31
32/// "These functions return zero if neither argument is NaN, and a and b are equal."
33/// Note that due to some kind of historical accident, __eqxf2 and __nexf2 are defined
34/// to have the same return value.
35fn __eqxf2(a: f80, b: f80) callconv(.c) i32 {
36 return __cmpxf2(a, b);
37}
38
39/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal."
40/// Note that due to some kind of historical accident, __eqxf2 and __nexf2 are defined
41/// to have the same return value.
42fn __nexf2(a: f80, b: f80) callconv(.c) i32 {
43 return __cmpxf2(a, b);
44}
45
46/// "These functions return a value less than zero if neither argument is NaN, and a
47/// is strictly less than b."
48fn __ltxf2(a: f80, b: f80) callconv(.c) i32 {
49 return __cmpxf2(a, b);
50}