-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.math.isnan output is different from comptime_float vs f32 #21198
Comments
I was looking into fixing this, since I found that it's due to this logic in Sema which is short-circuiting the evaluation process to yield zero when the numerator is zero in But while I was doing that, I came across 60c2972 which added a test specifically to ensure that Lines 1579 to 1581 in 7d54c62
It's unclear to me why this was done, since the commit message doesn't elaborate, and I don't see any mention of this special case in the langref. The existing compile error tests suggest that it is intended for other The same logic has some other potentially undesired effects (test passes as of 0.14.0-dev.1304+7d54c62c8): const std = @import("std");
const expect = std.testing.expect;
test {
// Existing test: comptime_float 0/0 is 0
try expect(0.0 / 0.0 == 0.0);
// Same thing applies to comptime_int and comptime-known ints:
try expect(0 / 0 == 0);
try expect(@as(u32, 0) / @as(u32, 0) == 0);
// Negative zero is lost when dividing comptime_floats:
try expect(std.math.isNegativeZero(@as(f128, -0.0) / @as(f128, 1.0))); // OK for f128
try expect(!std.math.isNegativeZero(@as(f128, -0.0 / 1.0))); // not for comptime_float (note isNegativeZero doesn't support comptime_float directly)
} The langref currently says that |
I moved my findings above to a proposal (#21205), since deciding how (or if) to fix this requires changing evidently intentional language features (as demonstrated by the linked test cases). |
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
OUTPUT:
Expected Behavior
I would expect
comptime_float
andf32
would result in the same output oftrue
.The text was updated successfully, but these errors were encountered: