#Unsigned -> signed integer casting
1 messages · Page 1 of 1 (latest)
just intcast it directly in this case, leave out the truncate
in the general case const foo: T = ... can be replaced in inline situations with @as(T, ...)
if your assumption turns out to he wrong, it will panic in debug mode or be UB in releasefast
couldn't work out how to get the truncate to infer type so thanks for that, think I'll accept the UB then if that's how zig handles it cheers
return @intCast(@as(u31, @truncate(properties.limit.maxImageDimension2D)));
but again, if you are truly confident that maxImageDimension2D will be 1 >> 31 or less, just leave off the truncate
but if you aren’t sure, instead of using truncate, i would use std.math.cast instead and return an error if the value doesnt fit