diff --git a/doc/langref.html.in b/doc/langref.html.in index f6c63e0672..774149b1c3 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -6641,19 +6641,19 @@ test "coercion from homogenous tuple to array" {
{#syntax#}@intFromBool(value: bool) u1{#endsyntax#}
- - Converts {#syntax#}true{#endsyntax#} to {#syntax#}@as(u1, 1){#endsyntax#} and {#syntax#}false{#endsyntax#} to - {#syntax#}@as(u1, 0){#endsyntax#}. -
- {#header_close#} - {#header_open|@bitSizeOf#}{#syntax#}@bitSizeOf(comptime T: type) comptime_int{#endsyntax#}
@@ -8351,6 +8343,7 @@ test "main" {
For a function that returns a possible error code, use {#syntax#}@import("std").math.divTrunc{#endsyntax#}.
{#see_also|@divFloor|@divExact#} {#header_close#} + {#header_open|@embedFile#}{#syntax#}@embedFile(comptime path: []const u8) *const [N:0]u8{#endsyntax#}
@@ -8366,17 +8359,32 @@ test "main" { {#see_also|@import#} {#header_close#} - {#header_open|@intFromEnum#} -
{#syntax#}@intFromEnum(enum_or_tagged_union: anytype) anytype{#endsyntax#}
+ {#header_open|@enumFromInt#}
+ {#syntax#}@enumFromInt(integer: anytype) anytype{#endsyntax#}
- Converts an enumeration value into its integer tag type. When a tagged union is passed, - the tag value is used as the enumeration value. + Converts an integer into an {#link|enum#} value. The return type is the inferred result type.
- If there is only one possible enum value, the result is a {#syntax#}comptime_int{#endsyntax#} - known at {#link|comptime#}. + Attempting to convert an integer which represents no value in the chosen enum type invokes + safety-checked {#link|Undefined Behavior#}.
- {#see_also|@enumFromInt#} + {#see_also|@intFromEnum#} + {#header_close#} + + {#header_open|@errorFromInt#} +{#syntax#}@errorFromInt(value: std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}
+ + Converts from the integer representation of an error into {#link|The Global Error Set#} type. +
++ It is generally recommended to avoid this + cast, as the integer representation of an error is not stable across source code changes. +
++ Attempting to convert an integer that does not correspond to any error results in + safety-protected {#link|Undefined Behavior#}. +
+ {#see_also|@intFromError#} {#header_close#} {#header_open|@errorName#} @@ -8401,26 +8409,6 @@ test "main" { {#header_close#} - {#header_open|@intFromError#} -{#syntax#}@intFromError(err: anytype) std.meta.Int(.unsigned, @sizeOf(anyerror) * 8){#endsyntax#}
- - Supports the following types: -
-- Converts an error to the integer representation of an error. -
-- It is generally recommended to avoid this - cast, as the integer representation of an error is not stable across source code changes. -
- {#see_also|@errorFromInt#} - {#header_close#} - {#header_open|@errSetCast#}{#syntax#}@errSetCast(value: anytype) anytype{#endsyntax#}
@@ -8545,16 +8533,12 @@ test "decl access by string" {
{#header_close#} - {#header_open|@intFromFloat#} -{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}
+ {#header_open|@floatFromInt#}
+ {#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}
- Converts the integer part of a floating point number to the inferred result type. + Converts an integer to the closest floating point representation. The return type is the inferred result type. + To convert the other way, use {#link|@intFromFloat#}. This cast is always safe.
-- If the integer part of the floating point number cannot fit in the destination type, - it invokes safety-checked {#link|Undefined Behavior#}. -
- {#see_also|@floatFromInt#} {#header_close#} {#header_open|@frameAddress#} @@ -8686,54 +8670,66 @@ test "integer cast panic" { {#header_close#} - {#header_open|@enumFromInt#} -{#syntax#}@enumFromInt(integer: anytype) anytype{#endsyntax#}
+ {#header_open|@intFromBool#}
+ {#syntax#}@intFromBool(value: bool) u1{#endsyntax#}
- Converts an integer into an {#link|enum#} value. The return type is the inferred result type. + Converts {#syntax#}true{#endsyntax#} to {#syntax#}@as(u1, 1){#endsyntax#} and {#syntax#}false{#endsyntax#} to + {#syntax#}@as(u1, 0){#endsyntax#}.
-- Attempting to convert an integer which represents no value in the chosen enum type invokes - safety-checked {#link|Undefined Behavior#}. -
- {#see_also|@intFromEnum#} {#header_close#} - {#header_open|@errorFromInt#} -{#syntax#}@errorFromInt(value: std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}
+ {#header_open|@intFromEnum#}
+ {#syntax#}@intFromEnum(enum_or_tagged_union: anytype) anytype{#endsyntax#}
- Converts from the integer representation of an error into {#link|The Global Error Set#} type. + Converts an enumeration value into its integer tag type. When a tagged union is passed, + the tag value is used as the enumeration value. +
++ If there is only one possible enum value, the result is a {#syntax#}comptime_int{#endsyntax#} + known at {#link|comptime#}. +
+ {#see_also|@enumFromInt#} + {#header_close#} + + {#header_open|@intFromError#} +{#syntax#}@intFromError(err: anytype) std.meta.Int(.unsigned, @sizeOf(anyerror) * 8){#endsyntax#}
+ + Supports the following types: +
++ Converts an error to the integer representation of an error.
It is generally recommended to avoid this cast, as the integer representation of an error is not stable across source code changes.
-- Attempting to convert an integer that does not correspond to any error results in - safety-protected {#link|Undefined Behavior#}. -
- {#see_also|@intFromError#} + {#see_also|@errorFromInt#} {#header_close#} - {#header_open|@floatFromInt#} -{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}
+ {#header_open|@intFromFloat#}
+ {#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}
- Converts an integer to the closest floating point representation. The return type is the inferred result type. - To convert the other way, use {#link|@intFromFloat#}. This cast is always safe. + Converts the integer part of a floating point number to the inferred result type.
++ If the integer part of the floating point number cannot fit in the destination type, + it invokes safety-checked {#link|Undefined Behavior#}. +
+ {#see_also|@floatFromInt#} {#header_close#} - {#header_open|@ptrFromInt#} -{#syntax#}@ptrFromInt(address: usize) anytype{#endsyntax#}
+ {#header_open|@intFromPtr#}
+ {#syntax#}@intFromPtr(value: anytype) usize{#endsyntax#}
- Converts an integer to a {#link|pointer|Pointers#}. The return type is the inferred result type. - To convert the other way, use {#link|@intFromPtr#}. Casting an address of 0 to a destination type - which in not {#link|optional|Optional Pointers#} and does not have the {#syntax#}allowzero{#endsyntax#} attribute will result in a - {#link|Pointer Cast Invalid Null#} panic when runtime safety checks are enabled. -
-- If the destination pointer type does not allow address zero and {#syntax#}address{#endsyntax#} - is zero, this invokes safety-checked {#link|Undefined Behavior#}. + Converts {#syntax#}value{#endsyntax#} to a {#syntax#}usize{#endsyntax#} which is the address of the pointer. + {#syntax#}value{#endsyntax#} can be {#syntax#}*T{#endsyntax#} or {#syntax#}?*T{#endsyntax#}.
+To convert the other way, use {#link|@ptrFromInt#}
{#header_close#} {#header_open|@max#} @@ -8950,14 +8946,18 @@ pub const PrefetchOptions = struct { {#header_close#} - {#header_open|@intFromPtr#} -{#syntax#}@intFromPtr(value: anytype) usize{#endsyntax#}
+ {#header_open|@ptrFromInt#}
+ {#syntax#}@ptrFromInt(address: usize) anytype{#endsyntax#}
- Converts {#syntax#}value{#endsyntax#} to a {#syntax#}usize{#endsyntax#} which is the address of the pointer. - {#syntax#}value{#endsyntax#} can be {#syntax#}*T{#endsyntax#} or {#syntax#}?*T{#endsyntax#}. + Converts an integer to a {#link|pointer|Pointers#}. The return type is the inferred result type. + To convert the other way, use {#link|@intFromPtr#}. Casting an address of 0 to a destination type + which in not {#link|optional|Optional Pointers#} and does not have the {#syntax#}allowzero{#endsyntax#} attribute will result in a + {#link|Pointer Cast Invalid Null#} panic when runtime safety checks are enabled. +
++ If the destination pointer type does not allow address zero and {#syntax#}address{#endsyntax#} + is zero, this invokes safety-checked {#link|Undefined Behavior#}.
-To convert the other way, use {#link|@ptrFromInt#}
- {#header_close#} {#header_open|@rem#}