diff --git a/doc/langref.html.in b/doc/langref.html.in index fc7f4c5461e6..3223308d42cb 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -5618,9 +5618,11 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val {#header_open|@round#}
{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}

- 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, rounds away from zero. + Uses a dedicated hardware instruction when available.

+ {#code|test_round_builtin.zig#} +

Supports {#link|Floats#} and {#link|Vectors#} of floats.

diff --git a/doc/langref/test_round_builtin.zig b/doc/langref/test_round_builtin.zig new file mode 100644 index 000000000000..a317ca79f03d --- /dev/null +++ b/doc/langref/test_round_builtin.zig @@ -0,0 +1,10 @@ +const expect = @import("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(-2.5) == -3); +} + +// test diff --git a/lib/std/math.zig b/lib/std/math.zig index 39e1a157da68..0c00818a1e91 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -1140,7 +1140,8 @@ test ByteAlignedInt { try testing.expect(ByteAlignedInt(u129) == u136); } -/// Rounds the given floating point number to an integer, away from zero. +/// 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. /// This is the same as calling the builtin @round pub inline fn round(value: anytype) @TypeOf(value) {