@mod with negative even numbers hits unreachable?
Ziggit
@mod with negative even numbers hits unreachable?
Hi, I’m new to Zig and trying to understand this. This version crashes: const std = @import("std"); pub fn main() void { const num = -2; // -4, -6, ... std.debug.print("{}\n", .{@mod(num, 2)}); switch (@mod(num, 2)) { 0 => std.debug.print("Even\n", .{}), 1 => std.debug.print("Odd\n", .{}), else => unreachable, } } Output: 0 thread panic: reached unreachable code What I’m seeing: Negative even const values → prints 0 but then crashes Negative odd ...
0 comments
No comments yet.