Curriculum Basics Numeric primitives
Numeric primitives
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.
9 ready
01
pick one TypeScript has one numeric type — number — for everything.
02
pick one In TypeScript, mixing number widths is invisible — they're
03
pick one When narrowing (a wider integer to a smaller one), @as won't
04
fill blanksFill the missing type name. The variable holds a pointer-sized
05
fill blanksFill the missing builtin name. The line forces the integer
06
type one line Type the missing Zig line — widen small: u8 to u32. Hint:
07
type one line Type the missing Zig line — the narrowing cast from i64 to
08
write a programWrite a complete Zig program that:
09
write a programWrite a complete Zig program that mixes integer widths: