| author | |
| committer | |
| log | eb7f318ea897d51082b70c84591242735c8a2c53 |
| tree | 3c77d9f03480a6fa5ec80cffc6ef5fa5884dbf36 |
| parent | b7a1ef3e19039690b182a295dff7cffe5fcc521f |
| signature |
A test has also been added to demonstrate the expected behavior.
* std.math: update round doc comment to match the builtin3 files changed, 16 insertions(+), 3 deletions(-)
doc/langref.html.in+4-2| ... | ... | @@ -5618,9 +5618,11 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5618 | 5618 | {#header_open|@round#} |
| 5619 | 5619 | <pre>{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}</pre> |
| 5620 | 5620 | <p> |
| 5621 | Rounds the given floating point number to an integer, away from zero. Uses a dedicated hardware instruction | |
| 5622 | when available. | |
| 5621 | Rounds the given floating point number to the nearest integer. If two integers are equally close, rounds away from zero. | |
| 5622 | Uses a dedicated hardware instruction when available. | |
| 5623 | 5623 | </p> |
| 5624 | {#code|test_round_builtin.zig#} | |
| 5625 | ||
| 5624 | 5626 | <p> |
| 5625 | 5627 | Supports {#link|Floats#} and {#link|Vectors#} of floats. |
| 5626 | 5628 | </p> |
doc/langref/test_round_builtin.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | ||
| 3 | test "@round" { | |
| 4 | try expect(@round(1.4) == 1); | |
| 5 | try expect(@round(1.5) == 2); | |
| 6 | try expect(@round(-1.4) == -1); | |
| 7 | try expect(@round(-2.5) == -3); | |
| 8 | } | |
| 9 | ||
| 10 | // test |
lib/std/math.zig+2-1| ... | ... | @@ -1140,7 +1140,8 @@ test ByteAlignedInt { |
| 1140 | 1140 | try testing.expect(ByteAlignedInt(u129) == u136); |
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | /// Rounds the given floating point number to an integer, away from zero. | |
| 1143 | /// Rounds the given floating point number to the nearest integer. | |
| 1144 | /// If two integers are equally close, rounds away from zero. | |
| 1144 | 1145 | /// Uses a dedicated hardware instruction when available. |
| 1145 | 1146 | /// This is the same as calling the builtin @round |
| 1146 | 1147 | pub inline fn round(value: anytype) @TypeOf(value) { |