zig icon indicating copy to clipboard operation
zig copied to clipboard

Incorrect documentation for std.math.round/@round

Open balvaldyr opened this issue 1 year ago • 1 comments

As per documentation the behaviour is described as such for std.math.round() and @round https://github.com/ziglang/zig/blob/956f53beb09c07925970453d4c178c6feb53ba70/lib/std/math.zig#L1217C50-L1217C57

/// Rounds the given floating point number to an integer, away from zero.
/// Uses a dedicated hardware instruction when available.
/// This is the same as calling the builtin @round

Based upon the documentation I would expect the following behaviour:

@round(0.4) == 1
@round(-2.3) == -3

However, these @round to 0 and -2 respectively.

Suggestion: Change the documentation to

/// Rounds the given floating point number to the nearest integer, in case of two equidistant integers it rounds away from zero.
/// Uses a dedicated hardware instruction when available.
/// This is the same as calling the builtin @round

balvaldyr avatar Apr 29 '24 20:04 balvaldyr

looks like theres already a pr for this https://github.com/ziglang/zig/pull/19503

xdBronch avatar Apr 29 '24 20:04 xdBronch