Remember to search before filing a new report
Zig Version
0.9.0-dev.1679+6cf8a49bb
Steps to Reproduce
Run zig translate-c on the following code:
#include <stdlib.h>
int main(void) {
int x = 5 % -2;
if (x != 1) abort();
}
And then zig run on the output
Expected Behavior
From the C standard: If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a. So in this case x should equal 1 and the program should exit normally.
Actual Behavior
Compile error:
./test.zig:1120:20: error: negative denominator
var x: c_int = @rem(@as(c_int, 5), -@as(c_int, 2));
Also, if the divisor is a runtime value instead of a comptime-known one, the result is a panic at runtime.
Remember to search before filing a new report
Zig Version
0.9.0-dev.1679+6cf8a49bb
Steps to Reproduce
Run
zig translate-con the following code:And then
zig runon the outputExpected Behavior
From the C standard:
If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a.So in this case x should equal 1 and the program should exit normally.Actual Behavior
Compile error:
Also, if the divisor is a runtime value instead of a comptime-known one, the result is a panic at runtime.