From 75457202d4d808da72015bf1c942255883236416 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
- Explicit casts are performed via {#link|Builtin Functions#}.
- Some explicit casts are safe; some are not.
- Some explicit casts perform language-level assertions; some do not.
- Some explicit casts are no-ops at runtime; some are not.
- Explicit casts are performed via {#link|Builtin Functions#}. Some explicit casts can violate type safety when used incorrectly. Some explicit casts perform language-level assertions. Some explicit casts are no-ops at runtime.
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 operation is legal
- for all values of all integer types.
+ To convert the other way, use {#link|@round#}, {#link|@floor#},
+ {#link|@ceil#}, or {#link|@trunc#}. This operation is legal for all
+ values of all integer types.
- 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|Illegal Behavior#}.
- Deprecated. Equivalent to {#link|@trunc#}.
{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}
{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}
-
{#syntax#}@floor(value: anytype) @TypeOf(value){#endsyntax#}
- - Returns the largest integral value not greater than the given floating point number. - Uses a dedicated hardware instruction when available. -
-- Supports {#link|Floats#} and {#link|Vectors#} of floats. -
+Returns the largest integral value not greater than the given floating point number. + Uses a dedicated hardware instruction when available.
+Supports {#link|Floats#} and {#link|Vectors#} of floats.
+When the inferred result type is an {#link|integer|Integers#}, + the integer part is extracted from the floored result. If that value + cannot fit in the destination type, it invokes safety-checked + {#link|Illegal Behavior#}.
{#header_close#} + {#header_open|@ceil#}{#syntax#}@ceil(value: anytype) @TypeOf(value){#endsyntax#}
- - Returns the smallest integral value not less than the given floating point number. - Uses a dedicated hardware instruction when available. -
-- Supports {#link|Floats#} and {#link|Vectors#} of floats. -
+Returns the smallest integral value not less than the given floating point number. + Uses a dedicated hardware instruction when available.
+Supports {#link|Floats#} and {#link|Vectors#} of floats.
+When the inferred result type is an {#link|integer|Integers#}, + the integer part is extracted from the ceiled result. If that value + cannot fit in the destination type, it invokes safety-checked + {#link|Illegal Behavior#}.
{#header_close#} + {#header_open|@trunc#}{#syntax#}@trunc(value: anytype) @TypeOf(value){#endsyntax#}
- - Rounds the given floating point number to an integer, towards zero. - Uses a dedicated hardware instruction when available. -
-- Supports {#link|Floats#} and {#link|Vectors#} of floats. -
+Rounds the given floating point number to an integer, towards zero. + Uses a dedicated hardware instruction when available.
+Supports {#link|Floats#} and {#link|Vectors#} of float parameters.
+When the inferred result type is an {#link|integer|Integers#}, + the integer part is extracted from the truncated result. If that value + cannot fit in the destination type, it invokes safety-checked + {#link|Illegal Behavior#}.
{#header_close#} + {#header_open|@round#}{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}
- - Rounds the given floating point number to the nearest integer. If two integers are equally close, rounds away from zero. - Uses a dedicated hardware instruction when available. -
+Rounds the given floating point number to the nearest integer. If two + integers are equally close, rounds away from zero. Uses a dedicated + hardware instruction when available.
{#code|test_round_builtin.zig#} - -- Supports {#link|Floats#} and {#link|Vectors#} of floats. -
+Supports {#link|Floats#} and {#link|Vectors#} of floats.
+When the inferred result type is an {#link|integer|Integers#}, + the integer part is extracted from the rounded result. If that value + cannot fit in the destination type, it invokes safety-checked + {#link|Illegal Behavior#}.
{#header_close#} {#header_open|@subWithOverflow#}