slovo/examples/numeric-widening-conversions.slo
2026-05-22 08:38:43 +02:00

33 lines
653 B
Plaintext

(module main)
(fn base_i64 () -> i64
(std.num.i32_to_i64 2147483647))
(fn widened_i64 () -> i64
(+ (base_i64) 1i64))
(fn half_step () -> f64
(+ (std.num.i32_to_f64 5) 0.5))
(fn wide_as_f64 () -> f64
(std.num.i64_to_f64 (widened_i64)))
(fn main () -> i32
(std.io.print_i64 (widened_i64))
(std.io.print_f64 (wide_as_f64))
(if (= (widened_i64) 2147483648i64)
0
1))
(test "i32 widens to i64"
(= (std.num.i32_to_i64 42) 42i64))
(test "i32 to i64 feeds i64 arithmetic"
(= (widened_i64) 2147483648i64))
(test "i32 widens to f64"
(= (std.num.i32_to_f64 42) 42.0))
(test "i64 widens to f64"
(= (wide_as_f64) 2147483648.0))