typeover
curriculum

Curriculum Foundations Numeric primitives exercise 5 · fill-word

Numeric primitives

Exercise 3 introduced Go's explicit-conversion shape — call the target type like a function. Now write it: an average of two integers needs both operands converted to a float before division, or you get integer division (which silently truncates). Fill the casts.

TypeScript reference
Fill the blanks →

About this theme

TypeScript has one number type. Go has many: int, int8, int16, int32, int64, uint* mirrors, float32, and float64. The big idea: Go has no implicit numeric conversion. A function expecting int64 will not accept an int32 without an explicit cast. This frustrates briefly, then becomes a feature.