LEARN VOID / 03
Types & numbers
Make the shape of data clear.
Complete program for the synchronous entry adapter. The result below is the returned integer.
func entry(minutes: i32) -> i32:
var seconds: i64 = (minutes as i64) * 60
return seconds as i32Choose the numeric representation
The input is minutes as i32; intermediate seconds use i64. Five minutes become 300 seconds. Signed integers are i8, i16, i32 and i64; unsigned integers use u8 through u64. Floating-point types are f32 and f64.
Convert explicitly
minutes as i64 converts an already typed value. The literal 60 takes its contextual i64 type. Returning through this CLI adapter requires seconds as i32. Conversions are checked: a value outside the target range raises a runtime failure. Integer arithmetic itself wraps.
Keep conditions and text explicit
bool holds true or false. Conditions require Boolean values; logical expressions use and, or and not. UTF-8 text uses string. These types do not introduce implicit numeric or text conversions.
Clamp values without an import
Keep a volume in the inclusive range zero through one hundred. Input 120 returns 100, negative input returns zero and an in-range input stays unchanged.
func entry(volume: i32) -> i32:
return volume.clamp(lower = 0, upper = 100)All ten numeric types provide T.min_value, T.max_value, T.abs(value) and T.clamp(value, lower, upper). Value forms such as volume.abs() and volume.clamp(0, 100) use the same operations. Signed-minimum absolute value and reversed clamp bounds fail with checked errors; NaN bounds also fail. Operations preserve the numeric type, without implicit widening. These are compiler-owned operations, available without a library import.