src: apply clang-tidy rule bugprone-incorrect-roundings by gengjiawen · Pull Request #26885 · nodejs/node (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation11 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
see https://clang.llvm.org/extra/clang-tidy/checks/bugprone-incorrect-roundings.html.
Checks the usage of patterns known to produce incorrect rounding. Programmers often use:
(int)(double_expression + 0.5)
to round the double expression to an integer. The problem with this:It is unnecessarily slow.
It is incorrect. The number 0.499999975 (smallest representable float number below 0.5) rounds to 1.0. Even worse behavior for negative numbers where both -0.5f and -1.4f both round to 0.0.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes- commit message follows commit guidelines
nodejs-github-bot added the c++
Issues and PRs that require attention from people who are familiar with C++.
label
PR-URL: nodejs#26885 Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Minwoo Jung minwoo@nodesource.com Reviewed-By: Refael Ackermann refack@gmail.com
BethGriggs pushed a commit that referenced this pull request
PR-URL: #26885 Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Minwoo Jung minwoo@nodesource.com Reviewed-By: Refael Ackermann refack@gmail.com
BethGriggs pushed a commit that referenced this pull request
PR-URL: #26885 Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Minwoo Jung minwoo@nodesource.com Reviewed-By: Refael Ackermann refack@gmail.com Signed-off-by: Beth Griggs Bethany.Griggs@uk.ibm.com
BethGriggs pushed a commit that referenced this pull request
PR-URL: #26885 Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Minwoo Jung minwoo@nodesource.com Reviewed-By: Refael Ackermann refack@gmail.com Signed-off-by: Beth Griggs Bethany.Griggs@uk.ibm.com
Labels
Issues and PRs that require attention from people who are familiar with C++.