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
Add math.round
; fix vector.round
#10803
Conversation
|
Technically, there are multiple ways of rounding a number. However, in practice, I have only ever learned or heard anyone use one rule: to round Different programming languages handle this differently. C and C++ round away from zero (like this PR), Python rounds towards zero (the opposite of this PR), JavaScript rounds towards positive infinity (like I don't care particularly much; I just chose this implementation because I thought it was the one most people were familiar with. I just thought it would be nice to have a rounding function built in. (I mean, we have
That's a typo on the PR description; I meant to say that |
I use round a lot. Necessary IMO. |
Following C++'s example makes sense, especially if you want to round node positions For reference:
I suggest not following Python's example |
Added docs saying it rounds away from zero at 0.5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds
math.round
to round to the nearest integer (simple, but useful), rounding away from zero at multiples of 0.5, as well as makingvector.round
follow this behaviour instead of rounding multiples of 0.5 towards +inf.Fixes #6774