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

add a fast and simple rounding function with given precision #29518

Closed
wants to merge 2 commits into from

Conversation

VinInn
Copy link
Contributor

@VinInn VinInn commented Apr 20, 2020

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

@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@VinInn VinInn changed the title add a fast and simple rounding function add a fast and simple rounding function with given precision Apr 20, 2020
@cmsbuild
Copy link
Contributor

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29518/14777

  • This PR adds an extra 16KB to repository

Code check has found code style and quality issues which could be resolved by applying following patch(s)

@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

// round with N significant bits
template <int N>
float roundAtPrecision(float x) {
if (edm::isNotFinite(x))
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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)

Copy link
Contributor Author

@VinInn VinInn Apr 20, 2020

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...

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29518/14779

  • This PR adds an extra 16KB to repository

@cmsbuild
Copy link
Contributor

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.
@makortel, @felicepantaleo, @fabiocos, @rovere this is something you requested to watch as well.
@silviodonato, @dpiparo you are the release manager for this.

cms-bot commands are listed here

@VinInn
Copy link
Contributor Author

VinInn commented Apr 20, 2020

duplicate of reduceMantissaToNbitsRounding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants