Numeric conversions
Convert an existing numeric value by calling the target type:
local count: Int = 42local compact = Int8(count)local unsigned = UInt32(count)local measurement = Float64(count)This is compiler-known syntax, not an ordinary overload or runtime lookup. It accepts exactly one numeric operand. Pop does not perform implicit widening between existing values.
Integer to integer
Section titled “Integer to integer”The result must fit the target’s exact range:
local wide: Int = 1_000local compact = UInt8(wide) -- traps: greater than 255Changing width or signedness is always explicit. Out-of-range conversion traps with NumericConversion; it never wraps.
Integer to floating point
Section titled “Integer to floating point”The conversion uses IEEE round-to-nearest, ties-to-even in the target format:
local count: UInt64 = 9_007_199_254_740_993local approximate = Float64(count)Large integers may round because a floating-point format cannot represent every integer in its range.
Floating point to integer
Section titled “Floating point to integer”Conversion truncates toward zero:
local positive = Int32(12.75) -- 12local negative = Int32(-12.75) -- -12NaN, infinity, and out-of-range results trap with NumericConversion.
Floating point width
Section titled “Floating point width”Float32 to Float64 is exact. Float64 to Float32 rounds to the target representation:
local compact: Float32 = 1.25local wide = Float64(compact)local compactAgain = Float32(wide)Converting a value to its own canonical numeric type preserves it.
