Curriculum Basics Numeric primitives exercise 2 · mcq
Numeric primitives
In TypeScript, mixing number widths is invisible — they're
all number. In Zig, the rule is more nuanced: SAFE
widening (smaller → larger, same sign) is implicit; lossy
conversions (narrowing, sign-changing in a way that could
lose information) need an explicit @intCast. Pick the
declaration that compiles AS-IS, no cast required.
About this theme
TypeScript has one numeric type — number — that swallows everything from booleans to billions. Zig is the opposite: every integer width is explicit (i8, i16, i32, i64, u8, u32, usize), every float too (f32, f64). The big rule: NO IMPLICIT LOSSY conversion. Safe widening is allowed (u8 → u32, i8 → i32); but narrowing or sign-changing conversions need an explicit cast. @as(T, x) is for explicit-clarity coercion (and for forcing a comptime literal to a specific runtime type); @intCast(x) is for narrowing — the target type is inferred from context.