#Unsigned -> signed integer casting

1 messages · Page 1 of 1 (latest)

unique temple
#

How can I make this a one-liner? Return type is i32 and maxImageDimension2D is u32 that I know will always be less than 1>>31

        const t: u31 = @truncate(properties.limits.maxImageDimension2D);
        return @intCast(t);
low pine
magic cosmos
#

in the general case const foo: T = ... can be replaced in inline situations with @as(T, ...)

low pine
unique temple
#

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

low pine
#

but again, if you are truly confident that maxImageDimension2D will be 1 >> 31 or less, just leave off the truncate

low pine