zig
zig copied to clipboard
Return a `usize` from `@abs` if given an `isize`
Also:
c_ushortforc_shortc_uintforc_intc_ulongforc_longc_ulonglongforc_longlong
Given an isize argument, @abs now returns a usize instead of a u* integer that has the same size as a pointer.
For example, @TypeOf(@abs(@as(isize, -1))) should produce usize instead of u64.
dont have stats on how common this is but felt it was worth mentioning this would break the following code
var x: isize = -24;
x = @abs(x);
That's already a compile error in current Zig:
prog.zig:6:6: error: expected type 'isize', found 'u64'
x = @abs(x);
^~~~~~~
prog.zig:6:6: note: signed 64-bit int cannot represent all possible unsigned 64-bit values
Pushed my src/Type.zig suggestion, and compacted the tests a bit. Thanks!