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

Fix overflow when rounding #42033

Merged
merged 1 commit into from
Sep 7, 2021
Merged

Conversation

petvana
Copy link
Member

@petvana petvana commented Aug 27, 2021

This PR aims to fix #37171. It simply uses a smaller step (square root of it) twice if it overflows. Otherwise, the computation remains exactly the same as before (and thus should not break any code).

Cc to the original author: @simonbyrne

The performance remains almost the same. Tested on i5-1035G1 by

for dig=1:7
    @btime round($(rand()), sigdigits = $dig)
end

Master:

  13.995 ns (0 allocations: 0 bytes)
  14.338 ns (0 allocations: 0 bytes)
  14.582 ns (0 allocations: 0 bytes)
  23.895 ns (0 allocations: 0 bytes)
  125.770 ns (0 allocations: 0 bytes)
  125.735 ns (0 allocations: 0 bytes)
  125.771 ns (0 allocations: 0 bytes)

This PR:

  14.233 ns (0 allocations: 0 bytes)
  14.536 ns (0 allocations: 0 bytes)
  15.044 ns (0 allocations: 0 bytes)
  24.183 ns (0 allocations: 0 bytes)
  126.037 ns (0 allocations: 0 bytes)
  126.018 ns (0 allocations: 0 bytes)
  126.134 ns (0 allocations: 0 bytes)

(The performance drop for 5+ digits is caused by the exponent while computing the step, see #42031)

@petvana petvana marked this pull request as ready for review August 27, 2021 17:13
@petvana
Copy link
Member Author

petvana commented Sep 3, 2021

@simonbyrne Would you mind checking this bugfix as the original author?

@simonbyrne simonbyrne merged commit 3aea11e into JuliaLang:master Sep 7, 2021
@simonbyrne
Copy link
Contributor

Thanks @petvana! Apologies for the delay.

LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overflow when rounding
2 participants