Curriculum Basics Numeric primitives exercise 1 · mcq
Numeric primitives
TypeScript has one numeric type — number — for everything.
Zig has many: signed integers (i8 to i128), unsigned
integers (u8 to u128), pointer-sized (isize / usize),
and floats (f32 / f64). Pick the right Zig width for each
scenario.
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.