authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-11 08:36:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-11 08:36:39-07:00
log75457202d4d808da72015bf1c942255883236416
tree71569483347212f669ebeca70ea018c35fa78928
parentcbe468a787e93d57ca64799e715ea7493f4a6ebb

langref: deprecate `@intFromFloat`

and add documentation for new semantics of `@round`, `@ceil`, `@floor`, and `@trunc`. follows #30906 relates #31602

1 files changed, 43 insertions(+), 46 deletions(-)

doc/langref.html.in+43-46
......@@ -3582,12 +3582,10 @@ void do_a_thing(struct Foo *foo) {
35823582 {#header_close#}
35833583
35843584 {#header_open|Explicit Casts#}
3585 <p>
3586 Explicit casts are performed via {#link|Builtin Functions#}.
3587 Some explicit casts are safe; some are not.
3588 Some explicit casts perform language-level assertions; some do not.
3589 Some explicit casts are no-ops at runtime; some are not.
3590 </p>
3585 <p>Explicit casts are performed via {#link|Builtin Functions#}.</p>
3586 <p>Some explicit casts can violate type safety when used incorrectly.</p>
3587 <p>Some explicit casts perform language-level assertions.</p>
3588 <p>Some explicit casts are no-ops at runtime.</p>
35913589 <ul>
35923590 <li>{#link|@bitCast#} - change type but maintain bit representation</li>
35933591 <li>{#link|@alignCast#} - make a pointer have more alignment</li>
......@@ -3600,7 +3598,7 @@ void do_a_thing(struct Foo *foo) {
36003598 <li>{#link|@intFromBool#} - convert true to 1 and false to 0</li>
36013599 <li>{#link|@intFromEnum#} - obtain the integer tag value of an enum or tagged union</li>
36023600 <li>{#link|@intFromError#} - obtain the integer value of an error code</li>
3603 <li>{#link|@intFromFloat#} - obtain the integer part of a float value</li>
3601 <li>{#link|@round#}, {#link|@floor#}, {#link|@ceil#}, {#link|@trunc#} - float to integer conversion</li>
36043602 <li>{#link|@intFromPtr#} - obtain the address of a pointer</li>
36053603 <li>{#link|@ptrFromInt#} - convert an address to a pointer</li>
36063604 <li>{#link|@ptrCast#} - convert between pointer types</li>
......@@ -4994,8 +4992,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
49944992 <pre>{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}</pre>
49954993 <p>
49964994 Converts an integer to the closest floating point representation. The return type is the inferred result type.
4997 To convert the other way, use {#link|@intFromFloat#}. This operation is legal
4998 for all values of all integer types.
4995 To convert the other way, use {#link|@round#}, {#link|@floor#},
4996 {#link|@ceil#}, or {#link|@trunc#}. This operation is legal for all
4997 values of all integer types.
49994998 </p>
50004999 {#header_close#}
50015000
......@@ -5135,14 +5134,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
51355134
51365135 {#header_open|@intFromFloat#}
51375136 <pre>{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}</pre>
5138 <p>
5139 Converts the integer part of a floating point number to the inferred result type.
5140 </p>
5141 <p>
5142 If the integer part of the floating point number cannot fit in the destination type,
5143 it invokes safety-checked {#link|Illegal Behavior#}.
5144 </p>
5145 {#see_also|@floatFromInt#}
5137 <p>Deprecated. Equivalent to {#link|@trunc#}.</p>
5138 {#see_also|@floatFromInt|@round|@floor|@ceil|@trunc#}
51465139 {#header_close#}
51475140
51485141 {#header_open|@intFromPtr#}
......@@ -5721,47 +5714,51 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
57215714 Supports {#link|Floats#}, {#link|Integers#} and {#link|Vectors#} of floats or integers.
57225715 </p>
57235716 {#header_close#}
5717
57245718 {#header_open|@floor#}
57255719 <pre>{#syntax#}@floor(value: anytype) @TypeOf(value){#endsyntax#}</pre>
5726 <p>
5727 Returns the largest integral value not greater than the given floating point number.
5728 Uses a dedicated hardware instruction when available.
5729 </p>
5730 <p>
5731 Supports {#link|Floats#} and {#link|Vectors#} of floats.
5732 </p>
5720 <p>Returns the largest integral value not greater than the given floating point number.
5721 Uses a dedicated hardware instruction when available.</p>
5722 <p>Supports {#link|Floats#} and {#link|Vectors#} of floats.</p>
5723 <p>When the inferred result type is an {#link|integer|Integers#},
5724 the integer part is extracted from the floored result. If that value
5725 cannot fit in the destination type, it invokes safety-checked
5726 {#link|Illegal Behavior#}.</p>
57335727 {#header_close#}
5728
57345729 {#header_open|@ceil#}
57355730 <pre>{#syntax#}@ceil(value: anytype) @TypeOf(value){#endsyntax#}</pre>
5736 <p>
5737 Returns the smallest integral value not less than the given floating point number.
5738 Uses a dedicated hardware instruction when available.
5739 </p>
5740 <p>
5741 Supports {#link|Floats#} and {#link|Vectors#} of floats.
5742 </p>
5731 <p>Returns the smallest integral value not less than the given floating point number.
5732 Uses a dedicated hardware instruction when available.</p>
5733 <p>Supports {#link|Floats#} and {#link|Vectors#} of floats.</p>
5734 <p>When the inferred result type is an {#link|integer|Integers#},
5735 the integer part is extracted from the ceiled result. If that value
5736 cannot fit in the destination type, it invokes safety-checked
5737 {#link|Illegal Behavior#}.</p>
57435738 {#header_close#}
5739
57445740 {#header_open|@trunc#}
57455741 <pre>{#syntax#}@trunc(value: anytype) @TypeOf(value){#endsyntax#}</pre>
5746 <p>
5747 Rounds the given floating point number to an integer, towards zero.
5748 Uses a dedicated hardware instruction when available.
5749 </p>
5750 <p>
5751 Supports {#link|Floats#} and {#link|Vectors#} of floats.
5752 </p>
5742 <p>Rounds the given floating point number to an integer, towards zero.
5743 Uses a dedicated hardware instruction when available.</p>
5744 <p>Supports {#link|Floats#} and {#link|Vectors#} of float parameters.</p>
5745 <p>When the inferred result type is an {#link|integer|Integers#},
5746 the integer part is extracted from the truncated result. If that value
5747 cannot fit in the destination type, it invokes safety-checked
5748 {#link|Illegal Behavior#}.</p>
57535749 {#header_close#}
5750
57545751 {#header_open|@round#}
57555752 <pre>{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}</pre>
5756 <p>
5757 Rounds the given floating point number to the nearest integer. If two integers are equally close, rounds away from zero.
5758 Uses a dedicated hardware instruction when available.
5759 </p>
5753 <p>Rounds the given floating point number to the nearest integer. If two
5754 integers are equally close, rounds away from zero. Uses a dedicated
5755 hardware instruction when available.</p>
57605756 {#code|test_round_builtin.zig#}
5761
5762 <p>
5763 Supports {#link|Floats#} and {#link|Vectors#} of floats.
5764 </p>
5757 <p>Supports {#link|Floats#} and {#link|Vectors#} of floats.</p>
5758 <p>When the inferred result type is an {#link|integer|Integers#},
5759 the integer part is extracted from the rounded result. If that value
5760 cannot fit in the destination type, it invokes safety-checked
5761 {#link|Illegal Behavior#}.</p>
57655762 {#header_close#}
57665763
57675764 {#header_open|@subWithOverflow#}