| ... | @@ -6641,19 +6641,19 @@ test "coercion from homogenous tuple to array" { | ... | @@ -6641,19 +6641,19 @@ test "coercion from homogenous tuple to array" { |
| 6641 | <ul> | 6641 | <ul> |
| 6642 | <li>{#link|@bitCast#} - change type but maintain bit representation</li> | 6642 | <li>{#link|@bitCast#} - change type but maintain bit representation</li> |
| 6643 | <li>{#link|@alignCast#} - make a pointer have more alignment</li> | 6643 | <li>{#link|@alignCast#} - make a pointer have more alignment</li> |
| | 6644 | <li>{#link|@enumFromInt#} - obtain an enum value based on its integer tag value</li> |
| | 6645 | <li>{#link|@errorFromInt#} - obtain an error code based on its integer value</li> |
| | 6646 | <li>{#link|@errSetCast#} - convert to a smaller error set</li> |
| | 6647 | <li>{#link|@floatCast#} - convert a larger float to a smaller float</li> |
| | 6648 | <li>{#link|@floatFromInt#} - convert an integer to a float value</li> |
| | 6649 | <li>{#link|@intCast#} - convert between integer types</li> |
| 6644 | <li>{#link|@intFromBool#} - convert true to 1 and false to 0</li> | 6650 | <li>{#link|@intFromBool#} - convert true to 1 and false to 0</li> |
| 6645 | <li>{#link|@intFromEnum#} - obtain the integer tag value of an enum or tagged union</li> | 6651 | <li>{#link|@intFromEnum#} - obtain the integer tag value of an enum or tagged union</li> |
| 6646 | <li>{#link|@errSetCast#} - convert to a smaller error set</li> | | |
| 6647 | <li>{#link|@intFromError#} - obtain the integer value of an error code</li> | 6652 | <li>{#link|@intFromError#} - obtain the integer value of an error code</li> |
| 6648 | <li>{#link|@floatCast#} - convert a larger float to a smaller float</li> | | |
| 6649 | <li>{#link|@intFromFloat#} - obtain the integer part of a float value</li> | 6653 | <li>{#link|@intFromFloat#} - obtain the integer part of a float value</li> |
| 6650 | <li>{#link|@intCast#} - convert between integer types</li> | 6654 | <li>{#link|@intFromPtr#} - obtain the address of a pointer</li> |
| 6651 | <li>{#link|@enumFromInt#} - obtain an enum value based on its integer tag value</li> | | |
| 6652 | <li>{#link|@errorFromInt#} - obtain an error code based on its integer value</li> | | |
| 6653 | <li>{#link|@floatFromInt#} - convert an integer to a float value</li> | | |
| 6654 | <li>{#link|@ptrFromInt#} - convert an address to a pointer</li> | 6655 | <li>{#link|@ptrFromInt#} - convert an address to a pointer</li> |
| 6655 | <li>{#link|@ptrCast#} - convert between pointer types</li> | 6656 | <li>{#link|@ptrCast#} - convert between pointer types</li> |
| 6656 | <li>{#link|@intFromPtr#} - obtain the address of a pointer</li> | | |
| 6657 | <li>{#link|@truncate#} - convert between integer types, chopping off bits</li> | 6657 | <li>{#link|@truncate#} - convert between integer types, chopping off bits</li> |
| 6658 | </ul> | 6658 | </ul> |
| 6659 | {#header_close#} | 6659 | {#header_close#} |
| ... | @@ -7902,14 +7902,6 @@ comptime { | ... | @@ -7902,14 +7902,6 @@ comptime { |
| 7902 | {#see_also|@offsetOf#} | 7902 | {#see_also|@offsetOf#} |
| 7903 | {#header_close#} | 7903 | {#header_close#} |
| 7904 | | 7904 | |
| 7905 | {#header_open|@intFromBool#} | | |
| 7906 | <pre>{#syntax#}@intFromBool(value: bool) u1{#endsyntax#}</pre> | | |
| 7907 | <p> | | |
| 7908 | Converts {#syntax#}true{#endsyntax#} to {#syntax#}@as(u1, 1){#endsyntax#} and {#syntax#}false{#endsyntax#} to | | |
| 7909 | {#syntax#}@as(u1, 0){#endsyntax#}. | | |
| 7910 | </p> | | |
| 7911 | {#header_close#} | | |
| 7912 | | | |
| 7913 | {#header_open|@bitSizeOf#} | 7905 | {#header_open|@bitSizeOf#} |
| 7914 | <pre>{#syntax#}@bitSizeOf(comptime T: type) comptime_int{#endsyntax#}</pre> | 7906 | <pre>{#syntax#}@bitSizeOf(comptime T: type) comptime_int{#endsyntax#}</pre> |
| 7915 | <p> | 7907 | <p> |
| ... | @@ -8351,6 +8343,7 @@ test "main" { | ... | @@ -8351,6 +8343,7 @@ test "main" { |
| 8351 | <p>For a function that returns a possible error code, use {#syntax#}@import("std").math.divTrunc{#endsyntax#}.</p> | 8343 | <p>For a function that returns a possible error code, use {#syntax#}@import("std").math.divTrunc{#endsyntax#}.</p> |
| 8352 | {#see_also|@divFloor|@divExact#} | 8344 | {#see_also|@divFloor|@divExact#} |
| 8353 | {#header_close#} | 8345 | {#header_close#} |
| | 8346 | |
| 8354 | {#header_open|@embedFile#} | 8347 | {#header_open|@embedFile#} |
| 8355 | <pre>{#syntax#}@embedFile(comptime path: []const u8) *const [N:0]u8{#endsyntax#}</pre> | 8348 | <pre>{#syntax#}@embedFile(comptime path: []const u8) *const [N:0]u8{#endsyntax#}</pre> |
| 8356 | <p> | 8349 | <p> |
| ... | @@ -8366,17 +8359,32 @@ test "main" { | ... | @@ -8366,17 +8359,32 @@ test "main" { |
| 8366 | {#see_also|@import#} | 8359 | {#see_also|@import#} |
| 8367 | {#header_close#} | 8360 | {#header_close#} |
| 8368 | | 8361 | |
| 8369 | {#header_open|@intFromEnum#} | 8362 | {#header_open|@enumFromInt#} |
| 8370 | <pre>{#syntax#}@intFromEnum(enum_or_tagged_union: anytype) anytype{#endsyntax#}</pre> | 8363 | <pre>{#syntax#}@enumFromInt(integer: anytype) anytype{#endsyntax#}</pre> |
| 8371 | <p> | 8364 | <p> |
| 8372 | Converts an enumeration value into its integer tag type. When a tagged union is passed, | 8365 | Converts an integer into an {#link|enum#} value. The return type is the inferred result type. |
| 8373 | the tag value is used as the enumeration value. | | |
| 8374 | </p> | 8366 | </p> |
| 8375 | <p> | 8367 | <p> |
| 8376 | If there is only one possible enum value, the result is a {#syntax#}comptime_int{#endsyntax#} | 8368 | Attempting to convert an integer which represents no value in the chosen enum type invokes |
| 8377 | known at {#link|comptime#}. | 8369 | safety-checked {#link|Undefined Behavior#}. |
| 8378 | </p> | 8370 | </p> |
| 8379 | {#see_also|@enumFromInt#} | 8371 | {#see_also|@intFromEnum#} |
| | 8372 | {#header_close#} |
| | 8373 | |
| | 8374 | {#header_open|@errorFromInt#} |
| | 8375 | <pre>{#syntax#}@errorFromInt(value: std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}</pre> |
| | 8376 | <p> |
| | 8377 | Converts from the integer representation of an error into {#link|The Global Error Set#} type. |
| | 8378 | </p> |
| | 8379 | <p> |
| | 8380 | It is generally recommended to avoid this |
| | 8381 | cast, as the integer representation of an error is not stable across source code changes. |
| | 8382 | </p> |
| | 8383 | <p> |
| | 8384 | Attempting to convert an integer that does not correspond to any error results in |
| | 8385 | safety-protected {#link|Undefined Behavior#}. |
| | 8386 | </p> |
| | 8387 | {#see_also|@intFromError#} |
| 8380 | {#header_close#} | 8388 | {#header_close#} |
| 8381 | | 8389 | |
| 8382 | {#header_open|@errorName#} | 8390 | {#header_open|@errorName#} |
| ... | @@ -8401,26 +8409,6 @@ test "main" { | ... | @@ -8401,26 +8409,6 @@ test "main" { |
| 8401 | </p> | 8409 | </p> |
| 8402 | {#header_close#} | 8410 | {#header_close#} |
| 8403 | | 8411 | |
| 8404 | {#header_open|@intFromError#} | | |
| 8405 | <pre>{#syntax#}@intFromError(err: anytype) std.meta.Int(.unsigned, @sizeOf(anyerror) * 8){#endsyntax#}</pre> | | |
| 8406 | <p> | | |
| 8407 | Supports the following types: | | |
| 8408 | </p> | | |
| 8409 | <ul> | | |
| 8410 | <li>{#link|The Global Error Set#}</li> | | |
| 8411 | <li>{#link|Error Set Type#}</li> | | |
| 8412 | <li>{#link|Error Union Type#}</li> | | |
| 8413 | </ul> | | |
| 8414 | <p> | | |
| 8415 | Converts an error to the integer representation of an error. | | |
| 8416 | </p> | | |
| 8417 | <p> | | |
| 8418 | It is generally recommended to avoid this | | |
| 8419 | cast, as the integer representation of an error is not stable across source code changes. | | |
| 8420 | </p> | | |
| 8421 | {#see_also|@errorFromInt#} | | |
| 8422 | {#header_close#} | | |
| 8423 | | | |
| 8424 | {#header_open|@errSetCast#} | 8412 | {#header_open|@errSetCast#} |
| 8425 | <pre>{#syntax#}@errSetCast(value: anytype) anytype{#endsyntax#}</pre> | 8413 | <pre>{#syntax#}@errSetCast(value: anytype) anytype{#endsyntax#}</pre> |
| 8426 | <p> | 8414 | <p> |
| ... | @@ -8545,16 +8533,12 @@ test "decl access by string" { | ... | @@ -8545,16 +8533,12 @@ test "decl access by string" { |
| 8545 | </p> | 8533 | </p> |
| 8546 | {#header_close#} | 8534 | {#header_close#} |
| 8547 | | 8535 | |
| 8548 | {#header_open|@intFromFloat#} | 8536 | {#header_open|@floatFromInt#} |
| 8549 | <pre>{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}</pre> | 8537 | <pre>{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}</pre> |
| 8550 | <p> | | |
| 8551 | Converts the integer part of a floating point number to the inferred result type. | | |
| 8552 | </p> | | |
| 8553 | <p> | 8538 | <p> |
| 8554 | If the integer part of the floating point number cannot fit in the destination type, | 8539 | Converts an integer to the closest floating point representation. The return type is the inferred result type. |
| 8555 | it invokes safety-checked {#link|Undefined Behavior#}. | 8540 | 			To convert the other way, use {#link|@intFromFloat#}. This cast is always safe. |
| 8556 | </p> | 8541 | </p> |
| 8557 | {#see_also|@floatFromInt#} | | |
| 8558 | {#header_close#} | 8542 | {#header_close#} |
| 8559 | | 8543 | |
| 8560 | {#header_open|@frameAddress#} | 8544 | {#header_open|@frameAddress#} |
| ... | @@ -8686,54 +8670,66 @@ test "integer cast panic" { | ... | @@ -8686,54 +8670,66 @@ test "integer cast panic" { |
| 8686 | </p> | 8670 | </p> |
| 8687 | {#header_close#} | 8671 | {#header_close#} |
| 8688 | | 8672 | |
| 8689 | {#header_open|@enumFromInt#} | 8673 | {#header_open|@intFromBool#} |
| 8690 | <pre>{#syntax#}@enumFromInt(integer: anytype) anytype{#endsyntax#}</pre> | 8674 | <pre>{#syntax#}@intFromBool(value: bool) u1{#endsyntax#}</pre> |
| 8691 | <p> | 8675 | <p> |
| 8692 | Converts an integer into an {#link|enum#} value. The return type is the inferred result type. | 8676 | Converts {#syntax#}true{#endsyntax#} to {#syntax#}@as(u1, 1){#endsyntax#} and {#syntax#}false{#endsyntax#} to |
| | 8677 | {#syntax#}@as(u1, 0){#endsyntax#}. |
| 8693 | </p> | 8678 | </p> |
| | 8679 | {#header_close#} |
| | 8680 | |
| | 8681 | {#header_open|@intFromEnum#} |
| | 8682 | <pre>{#syntax#}@intFromEnum(enum_or_tagged_union: anytype) anytype{#endsyntax#}</pre> |
| 8694 | <p> | 8683 | <p> |
| 8695 | Attempting to convert an integer which represents no value in the chosen enum type invokes | 8684 | Converts an enumeration value into its integer tag type. When a tagged union is passed, |
| 8696 | safety-checked {#link|Undefined Behavior#}. | 8685 | the tag value is used as the enumeration value. |
| 8697 | </p> | 8686 | </p> |
| 8698 | {#see_also|@intFromEnum#} | 8687 | <p> |
| | 8688 | If there is only one possible enum value, the result is a {#syntax#}comptime_int{#endsyntax#} |
| | 8689 | known at {#link|comptime#}. |
| | 8690 | </p> |
| | 8691 | {#see_also|@enumFromInt#} |
| 8699 | {#header_close#} | 8692 | {#header_close#} |
| 8700 | | 8693 | |
| 8701 | {#header_open|@errorFromInt#} | 8694 | {#header_open|@intFromError#} |
| 8702 | <pre>{#syntax#}@errorFromInt(value: std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}</pre> | 8695 | <pre>{#syntax#}@intFromError(err: anytype) std.meta.Int(.unsigned, @sizeOf(anyerror) * 8){#endsyntax#}</pre> |
| 8703 | <p> | 8696 | <p> |
| 8704 | Converts from the integer representation of an error into {#link|The Global Error Set#} type. | 8697 | Supports the following types: |
| 8705 | </p> | 8698 | </p> |
| | 8699 | <ul> |
| | 8700 | <li>{#link|The Global Error Set#}</li> |
| | 8701 | <li>{#link|Error Set Type#}</li> |
| | 8702 | <li>{#link|Error Union Type#}</li> |
| | 8703 | </ul> |
| 8706 | <p> | 8704 | <p> |
| 8707 | It is generally recommended to avoid this | 8705 | Converts an error to the integer representation of an error. |
| 8708 | cast, as the integer representation of an error is not stable across source code changes. | | |
| 8709 | </p> | 8706 | </p> |
| 8710 | <p> | 8707 | <p> |
| 8711 | Attempting to convert an integer that does not correspond to any error results in | 8708 | It is generally recommended to avoid this |
| 8712 | safety-protected {#link|Undefined Behavior#}. | 8709 | cast, as the integer representation of an error is not stable across source code changes. |
| 8713 | </p> | 8710 | </p> |
| 8714 | {#see_also|@intFromError#} | 8711 | {#see_also|@errorFromInt#} |
| 8715 | {#header_close#} | 8712 | {#header_close#} |
| 8716 | | 8713 | |
| 8717 | {#header_open|@floatFromInt#} | 8714 | {#header_open|@intFromFloat#} |
| 8718 | <pre>{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}</pre> | 8715 | <pre>{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}</pre> |
| 8719 | <p> | 8716 | <p> |
| 8720 | Converts an integer to the closest floating point representation. The return type is the inferred result type. | 8717 | Converts the integer part of a floating point number to the inferred result type. |
| 8721 | 			To convert the other way, use {#link|@intFromFloat#}. This cast is always safe. | | |
| 8722 | </p> | 8718 | </p> |
| 8723 | {#header_close#} | | |
| 8724 | | | |
| 8725 | {#header_open|@ptrFromInt#} | | |
| 8726 | <pre>{#syntax#}@ptrFromInt(address: usize) anytype{#endsyntax#}</pre> | | |
| 8727 | <p> | 8719 | <p> |
| 8728 | Converts an integer to a {#link|pointer|Pointers#}. The return type is the inferred result type. | 8720 | If the integer part of the floating point number cannot fit in the destination type, |
| 8729 | 			To convert the other way, use {#link|@intFromPtr#}. Casting an address of 0 to a destination type | 8721 | it invokes safety-checked {#link|Undefined Behavior#}. |
| 8730 | which in not {#link|optional|Optional Pointers#} and does not have the {#syntax#}allowzero{#endsyntax#} attribute will result in a | | |
| 8731 | {#link|Pointer Cast Invalid Null#} panic when runtime safety checks are enabled. | | |
| 8732 | </p> | 8722 | </p> |
| | 8723 | {#see_also|@floatFromInt#} |
| | 8724 | {#header_close#} |
| | 8725 | |
| | 8726 | {#header_open|@intFromPtr#} |
| | 8727 | <pre>{#syntax#}@intFromPtr(value: anytype) usize{#endsyntax#}</pre> |
| 8733 | <p> | 8728 | <p> |
| 8734 | If the destination pointer type does not allow address zero and {#syntax#}address{#endsyntax#} | 8729 | Converts {#syntax#}value{#endsyntax#} to a {#syntax#}usize{#endsyntax#} which is the address of the pointer. |
| 8735 | is zero, this invokes safety-checked {#link|Undefined Behavior#}. | 8730 | {#syntax#}value{#endsyntax#} can be {#syntax#}*T{#endsyntax#} or {#syntax#}?*T{#endsyntax#}. |
| 8736 | </p> | 8731 | </p> |
| | 8732 | <p>To convert the other way, use {#link|@ptrFromInt#}</p> |
| 8737 | {#header_close#} | 8733 | {#header_close#} |
| 8738 | | 8734 | |
| 8739 | {#header_open|@max#} | 8735 | {#header_open|@max#} |
| ... | @@ -8950,14 +8946,18 @@ pub const PrefetchOptions = struct { | ... | @@ -8950,14 +8946,18 @@ pub const PrefetchOptions = struct { |
| 8950 | </ul> | 8946 | </ul> |
| 8951 | {#header_close#} | 8947 | {#header_close#} |
| 8952 | | 8948 | |
| 8953 | {#header_open|@intFromPtr#} | 8949 | {#header_open|@ptrFromInt#} |
| 8954 | <pre>{#syntax#}@intFromPtr(value: anytype) usize{#endsyntax#}</pre> | 8950 | <pre>{#syntax#}@ptrFromInt(address: usize) anytype{#endsyntax#}</pre> |
| 8955 | <p> | 8951 | <p> |
| 8956 | Converts {#syntax#}value{#endsyntax#} to a {#syntax#}usize{#endsyntax#} which is the address of the pointer. | 8952 | Converts an integer to a {#link|pointer|Pointers#}. The return type is the inferred result type. |
| 8957 | {#syntax#}value{#endsyntax#} can be {#syntax#}*T{#endsyntax#} or {#syntax#}?*T{#endsyntax#}. | 8953 | 			To convert the other way, use {#link|@intFromPtr#}. Casting an address of 0 to a destination type |
| | 8954 | which in not {#link|optional|Optional Pointers#} and does not have the {#syntax#}allowzero{#endsyntax#} attribute will result in a |
| | 8955 | {#link|Pointer Cast Invalid Null#} panic when runtime safety checks are enabled. |
| | 8956 | </p> |
| | 8957 | <p> |
| | 8958 | If the destination pointer type does not allow address zero and {#syntax#}address{#endsyntax#} |
| | 8959 | is zero, this invokes safety-checked {#link|Undefined Behavior#}. |
| 8958 | </p> | 8960 | </p> |
| 8959 | <p>To convert the other way, use {#link|@ptrFromInt#}</p> | | |
| 8960 | | | |
| 8961 | {#header_close#} | 8961 | {#header_close#} |
| 8962 | | 8962 | |
| 8963 | {#header_open|@rem#} | 8963 | {#header_open|@rem#} |