zig icon indicating copy to clipboard operation
zig copied to clipboard

`>>` gives incorrect result at comptime when x < 0 and shift > log2(x)

Open topolarity opened this issue 3 years ago • 2 comments

Zig Version

0.10.0-dev.4430+f39f0fcac

Steps to Reproduce

const std = @import("std");
const expect = std.testing.expect;
test {
    var i: i8 = -3;
    try expect(i >> 2 == @as(i8, -3) >> 2);
}

Expected Behavior

Test should pass.

Actual Behavior

Test fails.

topolarity avatar Oct 17 '22 17:10 topolarity

what's the output if you use expectEqual ?

nektro avatar Oct 17 '22 17:10 nektro

At comptime @as(i8, -3) >> 2) == 0 but at runtime i >> 2 == -1

topolarity avatar Oct 17 '22 19:10 topolarity