-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorcompiler-rt
Milestone
Description
Zig Version
0.15.0-dev.833+5f7780c53
Steps to Reproduce and Observed Behavior
When the arguments are 0.0
and -0.0
, fmax
and fmin
do not care about the sign.
const std = @import("std");
fn compare_max() void {}
fn compare_min() void {}
test compare_max {
try std.testing.expect(@as(u64, @bitCast(@max(@as(f64, 0.0), @as(f64, -0.0)))) == @as(u64, @bitCast(@as(f64, 0.0)))); // This passes
try std.testing.expect(@as(u64, @bitCast(@max(@as(f64, -0.0), @as(f64, 0.0)))) == @as(u64, @bitCast(@as(f64, 0.0)))); // This fails
}
test compare_min {
try std.testing.expect(@as(u64, @bitCast(@min(@as(f64, 0.0), @as(f64, -0.0)))) == @as(u64, @bitCast(@as(f64, -0.0)))); // This passes
try std.testing.expect(@as(u64, @bitCast(@min(@as(f64, -0.0), @as(f64, 0.0)))) == @as(u64, @bitCast(@as(f64, -0.0)))); // This fails
}
$ zig test zero_comparison_test.zig
1/2 zero_comparison_test.decltest.compare_max...FAIL (TestUnexpectedResult)
/workspaces/Zig/zig/lib/std/testing.zig:586:14: 0x1033019 in expect (std.zig)
if (!ok) return error.TestUnexpectedResult;
^
/workspaces/Zig/mytest/zero_comparison_test.zig:9:5: 0x10330b3 in decltest.compare_max (zero_comparison_test.zig)
try std.testing.expect(@as(u64, @bitCast(@max(@as(f64, -0.0), @as(f64, 0.0)))) == @as(u64, @bitCast(@as(f64, 0.0)))); // This fails
^
2/2 zero_comparison_test.decltest.compare_min...FAIL (TestUnexpectedResult)
/workspaces/Zig/zig/lib/std/testing.zig:586:14: 0x1033019 in expect (std.zig)
if (!ok) return error.TestUnexpectedResult;
^
/workspaces/Zig/mytest/zero_comparison_test.zig:14:5: 0x1033264 in decltest.compare_min (zero_comparison_test.zig)
try std.testing.expect(@as(u64, @bitCast(@min(@as(f64, -0.0), @as(f64, 0.0)))) == @as(u64, @bitCast(@as(f64, -0.0)))); // This fails
^
0 passed; 0 skipped; 2 failed.
error: the following test command failed with exit code 1:
ISO/IEC 9899:1999(E) states that
Ideally, fmax would be sensitive to the sign of zero, for example fmax(−0.0, +0.0) would return +0; however, implementation in software might be impractical.
Actually musl's fmax
and fmin
behave ideally.
Expected Behavior
I expect these tests pass
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorcompiler-rt