You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect the unary -% to behave identically to @as(some_unsigned_type, 0) -% 1, but instead here's what I'm seeing:
Operation
Expected Result
Actual Result
@as(u32, 0) -% 1
std.math.maxInt(u32)
std.math.maxInt(u32)
-%@as(u32, 1)
std.math.maxInt(u32)
invalid wrapping negation type: 'u32'
-%1
(not sure... it's a comptime_int, maybe it just shouldn't wrap?)
0
The compilation error on -%@as(u32, 1) is particularly interesting. I can't link the source on GitHub since the file is 1.5 MiB big (!), but the failure happens in src/stage1/ir.cpp, inside ir_eval_negation_scalar():
I don't know why the requirement for scalar_type->data.integral.is_signed: the wrapping behavior is especially useful on unsigned types. A quick git blame indicates this check has existed since all the way back to 0ad580f.
The text was updated successfully, but these errors were encountered:
jmc-88
changed the title
Wrapping subtraction/negation oeprator oddities
Wrapping subtraction/negation operator oddities
Apr 19, 2021
The table of operators in the Zig documentation contains the following:
a -% b
a -%= b
@subWithOverflow
.@as(u32, 0) -% 1 == std.math.maxInt(u32)
-%a
-%@as(i32, std.math.minInt(i32)) == std.math.minInt(i32)
I would expect the unary
-%
to behave identically to@as(some_unsigned_type, 0) -% 1
, but instead here's what I'm seeing:@as(u32, 0) -% 1
std.math.maxInt(u32)
std.math.maxInt(u32)
-%@as(u32, 1)
std.math.maxInt(u32)
invalid wrapping negation type: 'u32'
-%1
comptime_int
, maybe it just shouldn't wrap?)0
The compilation error on
-%@as(u32, 1)
is particularly interesting. I can't link the source on GitHub since the file is 1.5 MiB big (!), but the failure happens insrc/stage1/ir.cpp
, insideir_eval_negation_scalar()
:I don't know why the requirement for
scalar_type->data.integral.is_signed
: the wrapping behavior is especially useful on unsigned types. A quickgit blame
indicates this check has existed since all the way back to 0ad580f.The text was updated successfully, but these errors were encountered: