Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No mention of round(2.5) == 2.0 behavior on overview of rounding functions (but present in docstring) #31943

Open
IanButterworth opened this issue May 6, 2019 · 4 comments
Labels
docs This change adds or pertains to documentation

Comments

@IanButterworth
Copy link
Member

The behavior round(2.5) == 2.0 comes as a surprise to me, and when I went to the online docs to understand why, the only information I got was round(x) | round x to the nearest integer here.

The docstring explains the issue (which remains odd default behavior to me) better, but it's a little hidden:

 round([T,] x, [r::RoundingMode])

 ...

  The RoundingMode r controls the direction of the rounding; the default is RoundNearest, which rounds to the nearest integer, with ties (fractional values of 0.5) being rounded to the nearest even integer.
...

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> round(1.7)
  2.0
  
  julia> round(Int, 1.7)
  2
  
  julia> round(1.5)
  2.0
  
  julia> round(2.5)
  2.0

IMO it needs to be a lot clearer in the online docs. There's no mention at all of this behavior, or of RoundingMode on https://docs.julialang.org/en/v1/manual/mathematical-operations/index.html#Rounding-functions-1

It would also be good to understand why this is the default behavior.. it goes against my intuition for rounding

@IanButterworth
Copy link
Member Author

IanButterworth commented May 6, 2019

@KristofferC I did get to the links you list, but I just worry that the simplistic description on the first page I landed on of round x to the nearest integer is overly simplistic, or perhaps inaccurate-enough to warrant a * and an explanation below of something like *except for ties (fractional values of 0.5), which are rounded to the nearest even integer, by default

@KristofferC
Copy link
Member

KristofferC commented May 6, 2019

They seem to be intentionally short descriptions. For those that want to read more they can always just go into the actual docstring. So to me, what needs to be fixed is that the links should go to the correct methods and not the Dates methods.

@JeffBezanson JeffBezanson added the docs This change adds or pertains to documentation label May 6, 2019
@IanButterworth IanButterworth changed the title No mention of round(2.5) == 2.0 behavior on online docs (but present in docstring) No mention of round(2.5) == 2.0 behavior on overview of rounding functions (but present in docstring) May 8, 2019
@IanButterworth
Copy link
Member Author

I guess concern is that round(x) is a function that most would mostly just use and that this behaviour at least for me, is unexpected. So perhaps the fact that the overview docs don't mention this is irrelevant as they wouldn't catch those that just use the function and get default behaviour.

More generally, the conclusion in #8750 seemed to be that numerical computing was moving towards defaulting to rounding ties to nearest even integer, so it's less of a Julia-specific issue anyway, and more of a general shift that I was unaware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

No branches or pull requests

3 participants