Skip to content

Commit

Permalink
langref: clarify functionality of the round builtin
Browse files Browse the repository at this point in the history
A test has also been added to demonstrate the expected behavior.
  • Loading branch information
torque committed Mar 31, 2024
1 parent a6ed3e6 commit 0f53a1c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -9673,9 +9673,20 @@ fn doTheTest() !void {
{#header_open|@round#}
<pre>{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Rounds the given floating point number to an integer, 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, round away from zero.
Uses a dedicated hardware instruction when available.
</p>
{#code_begin|test|test_round_builtin#}
const std = @import("std");
const expect = std.testing.expect;

test "@round" {
try expect(@round(1.4) == 1);
try expect(@round(1.5) == 2);
try expect(@round(-1.4) == -1);
try expect(@round(-1.5) == -2);
}
{#code_end#}
<p>
Supports {#link|Floats#} and {#link|Vectors#} of floats.
</p>
Expand Down

0 comments on commit 0f53a1c

Please sign in to comment.