zig

fork of https://codeberg.org/ziglang/zig
Log | Tree | Refs | README | LICENSE

commit f1bd59876872aad2be61a322eb07812b267a9997 (tree)
parent aea29afc448d8d93ca19e860c0c0b47c462e56a4
Author: Evin Yulo <yujiri@disroot.org>
Date:   Fri, 21 Jul 2023 09:17:58 -0400

langref: document out of bounds float to integer cast

Diffstat:
Mdoc/langref.html.in | 21++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git 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#} - <p>TODO</p> + <p> + This happens when casting a float to an integer where the float has a value outside the + integer type's range. + </p> + <p>At compile-time:</p> + {#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#} + <p>At runtime:</p> + {#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#}