From f1bd59876872aad2be61a322eb07812b267a9997 Mon Sep 17 00:00:00 2001 From: Evin Yulo Date: Fri, 21 Jul 2023 09:17:58 -0400 Subject: [PATCH] langref: document out of bounds float to integer cast --- doc/langref.html.in | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index d3db8079b5..b08e859f95 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -10387,7 +10387,26 @@ fn bar(f: *Foo) void { {#header_close#} {#header_open|Out of Bounds Float to Integer Cast#} -

TODO

+

+ This happens when casting a float to an integer where the float has a value outside the + integer type's range. +

+

At compile-time:

+ {#code_begin|test_err|test_comptime_out_of_bounds_float_to_integer_cast|float value '4294967296' cannot be stored in integer type 'i32'#} +comptime { + const float: f32 = 4294967296; + const int: i32 = @intFromFloat(float); + _ = int; +} + {#code_end#} +

At runtime:

+ {#code_begin|exe_err|runtime_out_of_bounds_float_to_integer_cast#} +pub fn main() void { + var float: f32 = 4294967296; + var int: i32 = @intFromFloat(float); + _ = int; +} + {#code_end#} {#header_close#} {#header_open|Pointer Cast Invalid Null#}