-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 a fast and simple rounding function with given precision #29518
Conversation
The code-checks are being triggered in jenkins. |
-code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29518/14777
Code check has found code style and quality issues which could be resolved by applying following patch(s)
|
The code-checks are being triggered in jenkins. |
// round with N significant bits | ||
template <int N> | ||
float roundAtPrecision(float x) { | ||
if (edm::isNotFinite(x)) |
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.
other than this, what is the performance difference wrt reduceMantissaToNbits in libminifloat?
I'd rather not proliferate. If this is better and the isNotFinite is the only difference, perhaps it's better to update reduceMantissaToNbits
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.
reduceMantissaToNbits just truncate.
reduceMantissaToNbitsRounding most probably is numerically equivalent even if the code looks more complex
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.
but isn't this code actually a truncation?
I see the unit test assert(roundAtPrecision<0>(2.9) == 2.f);
(round(2.9) = 3)
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.
It is a binary rounding
with only exponent (0 signficant bits) you have to choose between 2 and 4
so 2.9 rounds to 2 and pi to 4...
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29518/14779
|
A new Pull Request was created by @VinInn (Vincenzo Innocente) for master. It involves the following packages: DataFormats/Math @perrotta, @cmsbuild, @slava77 can you please review it and eventually sign? Thanks. cms-bot commands are listed here |
duplicate of reduceMantissaToNbitsRounding |
As discussed in #29513 it would be useful to have a fast and simple function to round a floating point number to a given precision of N bits.
here is it!
compiler will simplify it in just 2 integer instructions
https://godbolt.org/z/rpBkVS