| author | |
| committer | |
| log | 9e340b3005975e87563566a223d2f98e070f12cb |
| tree | 24bd9ac8339ebeafdb8ec79a37cf883e660bde8b |
| parent | 14ad8378a19dbbf84e0be491292019356b9e8752 |
-0.0, making it compatible with musl.2 files changed, 12 insertions(+), 0 deletions(-)
lib/compiler_rt/fmax.zig+6| ... | ... | @@ -54,12 +54,15 @@ inline fn generic_fmax(comptime T: type, x: T, y: T) T { |
| 54 | 54 | return y; |
| 55 | 55 | if (math.isNan(y)) |
| 56 | 56 | return x; |
| 57 | if (math.signbit(x) != math.signbit(y)) | |
| 58 | return if (math.signbit(x)) y else x; | |
| 57 | 59 | return if (x < y) y else x; |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | test "generic_fmax" { |
| 61 | 63 | inline for ([_]type{ f32, f64, c_longdouble, f80, f128 }) |T| { |
| 62 | 64 | const nan_val = math.nan(T); |
| 65 | const Int = std.meta.Int(.unsigned, @bitSizeOf(T)); | |
| 63 | 66 | |
| 64 | 67 | try std.testing.expect(math.isNan(generic_fmax(T, nan_val, nan_val))); |
| 65 | 68 | try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0)); |
| ... | ... | @@ -67,5 +70,8 @@ test "generic_fmax" { |
| 67 | 70 | |
| 68 | 71 | try std.testing.expectEqual(@as(T, 10.0), generic_fmax(T, 1.0, 10.0)); |
| 69 | 72 | try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0)); |
| 73 | ||
| 74 | try std.testing.expectEqual(@as(Int, @bitCast(@as(T, 0.0))), @as(Int, @bitCast(generic_fmax(T, 0.0, -0.0)))); | |
| 75 | try std.testing.expectEqual(@as(Int, @bitCast(@as(T, 0.0))), @as(Int, @bitCast(generic_fmax(T, -0.0, 0.0)))); | |
| 70 | 76 | } |
| 71 | 77 | } |
lib/compiler_rt/fmin.zig+6| ... | ... | @@ -54,12 +54,15 @@ inline fn generic_fmin(comptime T: type, x: T, y: T) T { |
| 54 | 54 | return y; |
| 55 | 55 | if (math.isNan(y)) |
| 56 | 56 | return x; |
| 57 | if (math.signbit(x) != math.signbit(y)) | |
| 58 | return if (math.signbit(x)) x else y; | |
| 57 | 59 | return if (x < y) x else y; |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | test "generic_fmin" { |
| 61 | 63 | inline for ([_]type{ f32, f64, c_longdouble, f80, f128 }) |T| { |
| 62 | 64 | const nan_val = math.nan(T); |
| 65 | const Int = std.meta.Int(.unsigned, @bitSizeOf(T)); | |
| 63 | 66 | |
| 64 | 67 | try std.testing.expect(math.isNan(generic_fmin(T, nan_val, nan_val))); |
| 65 | 68 | try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0)); |
| ... | ... | @@ -67,5 +70,8 @@ test "generic_fmin" { |
| 67 | 70 | |
| 68 | 71 | try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, 10.0)); |
| 69 | 72 | try std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0)); |
| 73 | ||
| 74 | try std.testing.expectEqual(@as(Int, @bitCast(@as(T, -0.0))), @as(Int, @bitCast(generic_fmin(T, 0.0, -0.0)))); | |
| 75 | try std.testing.expectEqual(@as(Int, @bitCast(@as(T, -0.0))), @as(Int, @bitCast(generic_fmin(T, -0.0, 0.0)))); | |
| 70 | 76 | } |
| 71 | 77 | } |