Language reference
Numbers and conversions
Choose numeric types and understand checked arithmetic.
Kalandra has ten native numeric types. Signed integers are int8, int16, int32 and int64; unsigned integers are uint8, uint16, uint32 and uint64. The floating-point types are float32 and float64.
Aliases and literal context
Across targets, int means int64, uint means uint64 and float means float64. These aliases are not pointer-sized. Whole-number literals normally infer int, and decimal or exponent literals normally infer float. An explicit annotation supplies the literal context:
fn main() -> int32:
left: int32 = 20
right: int32 = 22
left + right This returns 42 as an int32. Already typed values do not silently promote to a common numeric type. Convert deliberately when crossing widths or integer/floating families.
Explicit conversion
fn main() -> int32:
sample: float64 = 42.75
int32(sample) This returns 42. Float-to-integer conversion truncates toward zero and fails for NaN, infinity or an out-of-range result. Integer-to-integer conversion checks the destination range. Integer-to-float and float narrowing follow the specified rounding rules rather than promising exact representation for every input.
Arithmetic is checked
Integer overflow, invalid integer division and invalid conversions produce checked faults. Optimization does not turn signed overflow into wrapping behavior or remove range checks. Floating-point results follow the arithmetic and matrix policies described below.
Arithmetic and comparisons require compatible types. Numeric arrays and tensors keep a single element type; converting a tensor preserves its shape. GPU support also depends on the operation and device. Check the numerical guide when moving calculations to a GPU.
Arithmetic execution policy
CPU float32 and float64 arithmetic use hardware floating-point instructions by default. Floating comparisons and checked conversions also use hardware where supported. Integer overflow and conversion range checks remain enabled.
Use --arithmetic software to select the strict integer-based floating implementation. Hardware mode follows the target floating environment and does not promise identical subnormal, NaN or rounding behavior across all devices. reduceSum keeps its balanced order, and ordinary scalar and elementwise operations keep separate multiply/add behavior. Hardware GPU float32 matmul may use fused and reordered accumulation unless you select --matmul-policy fixed-tree; CPU matmul retains its fixed tree under either policy. -O2 does not enable generic fast math.