| ... | ... | @@ -3582,12 +3582,10 @@ void do_a_thing(struct Foo *foo) { |
| 3582 | 3582 | {#header_close#} |
| 3583 | 3583 | |
| 3584 | 3584 | {#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> |
| 3591 | 3589 | <ul> |
| 3592 | 3590 | <li>{#link|@bitCast#} - change type but maintain bit representation</li> |
| 3593 | 3591 | <li>{#link|@alignCast#} - make a pointer have more alignment</li> |
| ... | ... | @@ -3600,7 +3598,7 @@ void do_a_thing(struct Foo *foo) { |
| 3600 | 3598 | <li>{#link|@intFromBool#} - convert true to 1 and false to 0</li> |
| 3601 | 3599 | <li>{#link|@intFromEnum#} - obtain the integer tag value of an enum or tagged union</li> |
| 3602 | 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 | 3602 | <li>{#link|@intFromPtr#} - obtain the address of a pointer</li> |
| 3605 | 3603 | <li>{#link|@ptrFromInt#} - convert an address to a pointer</li> |
| 3606 | 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 | 4992 | <pre>{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}</pre> |
| 4995 | 4993 | <p> |
| 4996 | 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 |
| 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. |
| 4999 | 4998 | </p> |
| 5000 | 4999 | {#header_close#} |
| 5001 | 5000 | |
| ... | ... | @@ -5135,14 +5134,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5135 | 5134 | |
| 5136 | 5135 | {#header_open|@intFromFloat#} |
| 5137 | 5136 | <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#} |
| 5146 | 5139 | {#header_close#} |
| 5147 | 5140 | |
| 5148 | 5141 | {#header_open|@intFromPtr#} |
| ... | ... | @@ -5721,47 +5714,51 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5721 | 5714 | Supports {#link|Floats#}, {#link|Integers#} and {#link|Vectors#} of floats or integers. |
| 5722 | 5715 | </p> |
| 5723 | 5716 | {#header_close#} |
| 5717 | |
| 5724 | 5718 | {#header_open|@floor#} |
| 5725 | 5719 | <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> |
| 5733 | 5727 | {#header_close#} |
| 5728 | |
| 5734 | 5729 | {#header_open|@ceil#} |
| 5735 | 5730 | <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> |
| 5743 | 5738 | {#header_close#} |
| 5739 | |
| 5744 | 5740 | {#header_open|@trunc#} |
| 5745 | 5741 | <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> |
| 5753 | 5749 | {#header_close#} |
| 5750 | |
| 5754 | 5751 | {#header_open|@round#} |
| 5755 | 5752 | <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> |
| 5760 | 5756 | {#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> |
| 5765 | 5762 | {#header_close#} |
| 5766 | 5763 | |
| 5767 | 5764 | {#header_open|@subWithOverflow#} |