authorgravatar for yujiri@disroot.orgEvin Yulo <yujiri@disroot.org> 2023-07-21 09:17:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-24 12:57:11-07:00
logf1bd59876872aad2be61a322eb07812b267a9997
treea28a8b05dd36fb27bd15da76c8c0fe3d58771423
parentaea29afc448d8d93ca19e860c0c0b47c462e56a4

langref: document out of bounds float to integer cast


1 files changed, 20 insertions(+), 1 deletions(-)

doc/langref.html.in+20-1
......@@ -10387,7 +10387,26 @@ fn bar(f: *Foo) void {
1038710387 {#header_close#}
1038810388
1038910389 {#header_open|Out of Bounds Float to Integer Cast#}
10390 <p>TODO</p>
10390 <p>
10391 This happens when casting a float to an integer where the float has a value outside the
10392 integer type's range.
10393 </p>
10394 <p>At compile-time:</p>
10395 {#code_begin|test_err|test_comptime_out_of_bounds_float_to_integer_cast|float value '4294967296' cannot be stored in integer type 'i32'#}
10396comptime {
10397 const float: f32 = 4294967296;
10398 const int: i32 = @intFromFloat(float);
10399 _ = int;
10400}
10401 {#code_end#}
10402 <p>At runtime:</p>
10403 {#code_begin|exe_err|runtime_out_of_bounds_float_to_integer_cast#}
10404pub fn main() void {
10405 var float: f32 = 4294967296;
10406 var int: i32 = @intFromFloat(float);
10407 _ = int;
10408}
10409 {#code_end#}
1039110410 {#header_close#}
1039210411
1039310412 {#header_open|Pointer Cast Invalid Null#}