| ... | @@ -3582,12 +3582,10 @@ void do_a_thing(struct Foo *foo) { | ... | @@ -3582,12 +3582,10 @@ void do_a_thing(struct Foo *foo) { |
| 3582 | {#header_close#} | 3582 | {#header_close#} |
| 3583 | | 3583 | |
| 3584 | {#header_open|Explicit Casts#} | 3584 | {#header_open|Explicit Casts#} |
| 3585 | <p> | 3585 | <p>Explicit casts are performed via {#link|Builtin Functions#}.</p> |
| 3586 | Explicit casts are performed via {#link|Builtin Functions#}. | 3586 | <p>Some explicit casts can violate type safety when used incorrectly.</p> |
| 3587 | Some explicit casts are safe; some are not. | 3587 | <p>Some explicit casts perform language-level assertions.</p> |
| 3588 | Some explicit casts perform language-level assertions; some do not. | 3588 | <p>Some explicit casts are no-ops at runtime.</p> |
| 3589 | Some explicit casts are no-ops at runtime; some are not. | | |
| 3590 | </p> | | |
| 3591 | <ul> | 3589 | <ul> |
| 3592 | <li>{#link|@bitCast#} - change type but maintain bit representation</li> | 3590 | <li>{#link|@bitCast#} - change type but maintain bit representation</li> |
| 3593 | <li>{#link|@alignCast#} - make a pointer have more alignment</li> | 3591 | <li>{#link|@alignCast#} - make a pointer have more alignment</li> |
| ... | @@ -3600,7 +3598,7 @@ void do_a_thing(struct Foo *foo) { | ... | @@ -3600,7 +3598,7 @@ void do_a_thing(struct Foo *foo) { |
| 3600 | <li>{#link|@intFromBool#} - convert true to 1 and false to 0</li> | 3598 | <li>{#link|@intFromBool#} - convert true to 1 and false to 0</li> |
| 3601 | <li>{#link|@intFromEnum#} - obtain the integer tag value of an enum or tagged union</li> | 3599 | <li>{#link|@intFromEnum#} - obtain the integer tag value of an enum or tagged union</li> |
| 3602 | <li>{#link|@intFromError#} - obtain the integer value of an error code</li> | 3600 | <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> |
| 3604 | <li>{#link|@intFromPtr#} - obtain the address of a pointer</li> | 3602 | <li>{#link|@intFromPtr#} - obtain the address of a pointer</li> |
| 3605 | <li>{#link|@ptrFromInt#} - convert an address to a pointer</li> | 3603 | <li>{#link|@ptrFromInt#} - convert an address to a pointer</li> |
| 3606 | <li>{#link|@ptrCast#} - convert between pointer types</li> | 3604 | <li>{#link|@ptrCast#} - convert between pointer types</li> |
| ... | @@ -4994,8 +4992,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val | ... | @@ -4994,8 +4992,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 4994 | <pre>{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}</pre> | 4992 | <pre>{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}</pre> |
| 4995 | <p> | 4993 | <p> |
| 4996 | Converts an integer to the closest floating point representation. The return type is the inferred result type. | 4994 | 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 | 4995 | To convert the other way, use {#link|@round#}, {#link|@floor#}, |
| 4998 | for all values of all integer types. | 4996 | {#link|@ceil#}, or {#link|@trunc#}. This operation is legal for all |
| | 4997 | values of all integer types. |
| 4999 | </p> | 4998 | </p> |
| 5000 | {#header_close#} | 4999 | {#header_close#} |
| 5001 | | 5000 | |
| ... | @@ -5135,14 +5134,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val | ... | @@ -5135,14 +5134,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5135 | | 5134 | |
| 5136 | {#header_open|@intFromFloat#} | 5135 | {#header_open|@intFromFloat#} |
| 5137 | <pre>{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}</pre> | 5136 | <pre>{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}</pre> |
| 5138 | <p> | 5137 | <p>Deprecated. Equivalent to {#link|@trunc#}.</p> |
| 5139 | Converts the integer part of a floating point number to the inferred result type. | 5138 | {#see_also|@floatFromInt|@round|@floor|@ceil|@trunc#} |
| 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#} | | |
| 5146 | {#header_close#} | 5139 | {#header_close#} |
| 5147 | | 5140 | |
| 5148 | {#header_open|@intFromPtr#} | 5141 | {#header_open|@intFromPtr#} |
| ... | @@ -5721,47 +5714,51 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val | ... | @@ -5721,47 +5714,51 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5721 | Supports {#link|Floats#}, {#link|Integers#} and {#link|Vectors#} of floats or integers. | 5714 | Supports {#link|Floats#}, {#link|Integers#} and {#link|Vectors#} of floats or integers. |
| 5722 | </p> | 5715 | </p> |
| 5723 | {#header_close#} | 5716 | {#header_close#} |
| | 5717 | |
| 5724 | {#header_open|@floor#} | 5718 | {#header_open|@floor#} |
| 5725 | <pre>{#syntax#}@floor(value: anytype) @TypeOf(value){#endsyntax#}</pre> | 5719 | <pre>{#syntax#}@floor(value: anytype) @TypeOf(value){#endsyntax#}</pre> |
| 5726 | <p> | 5720 | <p>Returns the largest integral value not greater than the given floating point number. |
| 5727 | Returns the largest integral value not greater than the given floating point number. | 5721 | Uses a dedicated hardware instruction when available.</p> |
| 5728 | Uses a dedicated hardware instruction when available. | 5722 | <p>Supports {#link|Floats#} and {#link|Vectors#} of floats.</p> |
| 5729 | </p> | 5723 | <p>When the inferred result type is an {#link|integer|Integers#}, |
| 5730 | <p> | 5724 | the integer part is extracted from the floored result. If that value |
| 5731 | Supports {#link|Floats#} and {#link|Vectors#} of floats. | 5725 | cannot fit in the destination type, it invokes safety-checked |
| 5732 | </p> | 5726 | {#link|Illegal Behavior#}.</p> |
| 5733 | {#header_close#} | 5727 | {#header_close#} |
| | 5728 | |
| 5734 | {#header_open|@ceil#} | 5729 | {#header_open|@ceil#} |
| 5735 | <pre>{#syntax#}@ceil(value: anytype) @TypeOf(value){#endsyntax#}</pre> | 5730 | <pre>{#syntax#}@ceil(value: anytype) @TypeOf(value){#endsyntax#}</pre> |
| 5736 | <p> | 5731 | <p>Returns the smallest integral value not less than the given floating point number. |
| 5737 | Returns the smallest integral value not less than the given floating point number. | 5732 | Uses a dedicated hardware instruction when available.</p> |
| 5738 | Uses a dedicated hardware instruction when available. | 5733 | <p>Supports {#link|Floats#} and {#link|Vectors#} of floats.</p> |
| 5739 | </p> | 5734 | <p>When the inferred result type is an {#link|integer|Integers#}, |
| 5740 | <p> | 5735 | the integer part is extracted from the ceiled result. If that value |
| 5741 | Supports {#link|Floats#} and {#link|Vectors#} of floats. | 5736 | cannot fit in the destination type, it invokes safety-checked |
| 5742 | </p> | 5737 | {#link|Illegal Behavior#}.</p> |
| 5743 | {#header_close#} | 5738 | {#header_close#} |
| | 5739 | |
| 5744 | {#header_open|@trunc#} | 5740 | {#header_open|@trunc#} |
| 5745 | <pre>{#syntax#}@trunc(value: anytype) @TypeOf(value){#endsyntax#}</pre> | 5741 | <pre>{#syntax#}@trunc(value: anytype) @TypeOf(value){#endsyntax#}</pre> |
| 5746 | <p> | 5742 | <p>Rounds the given floating point number to an integer, towards zero. |
| 5747 | Rounds the given floating point number to an integer, towards zero. | 5743 | Uses a dedicated hardware instruction when available.</p> |
| 5748 | Uses a dedicated hardware instruction when available. | 5744 | <p>Supports {#link|Floats#} and {#link|Vectors#} of float parameters.</p> |
| 5749 | </p> | 5745 | <p>When the inferred result type is an {#link|integer|Integers#}, |
| 5750 | <p> | 5746 | the integer part is extracted from the truncated result. If that value |
| 5751 | Supports {#link|Floats#} and {#link|Vectors#} of floats. | 5747 | cannot fit in the destination type, it invokes safety-checked |
| 5752 | </p> | 5748 | {#link|Illegal Behavior#}.</p> |
| 5753 | {#header_close#} | 5749 | {#header_close#} |
| | 5750 | |
| 5754 | {#header_open|@round#} | 5751 | {#header_open|@round#} |
| 5755 | <pre>{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}</pre> | 5752 | <pre>{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}</pre> |
| 5756 | <p> | 5753 | <p>Rounds the given floating point number to the nearest integer. If two |
| 5757 | Rounds the given floating point number to the nearest integer. If two integers are equally close, rounds away from zero. | 5754 | integers are equally close, rounds away from zero. Uses a dedicated |
| 5758 | Uses a dedicated hardware instruction when available. | 5755 | hardware instruction when available.</p> |
| 5759 | </p> | | |
| 5760 | {#code|test_round_builtin.zig#} | 5756 | {#code|test_round_builtin.zig#} |
| 5761 | | 5757 | <p>Supports {#link|Floats#} and {#link|Vectors#} of floats.</p> |
| 5762 | <p> | 5758 | <p>When the inferred result type is an {#link|integer|Integers#}, |
| 5763 | Supports {#link|Floats#} and {#link|Vectors#} of floats. | 5759 | the integer part is extracted from the rounded result. If that value |
| 5764 | </p> | 5760 | cannot fit in the destination type, it invokes safety-checked |
| | 5761 | {#link|Illegal Behavior#}.</p> |
| 5765 | {#header_close#} | 5762 | {#header_close#} |
| 5766 | | 5763 | |
| 5767 | {#header_open|@subWithOverflow#} | 5764 | {#header_open|@subWithOverflow#} |