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 digits(n::Unsigned) with neg base for n > typemax(n)÷2 #29205

Merged
merged 1 commit into from
Sep 17, 2018

Conversation

StefanKarpinski
Copy link
Member

Alternative based on #29187

@StefanKarpinski StefanKarpinski force-pushed the sk/digits-unsigned branch 2 times, most recently from 731f384 to 0a9bc41 Compare September 15, 2018 22:51
# manually peel one loop iteration for type stability
n, d = fldmod(n, -base)
a[firstindex(a)] = d
n = -signed(n)
Copy link
Member

@rfourquet rfourquet Sep 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is type unstable, but maybe the compiler is good enough to handle that, or that the the cost of the divisions makes this negligible?
EDIT: after some very basic benchmarking, this doesn't seem indeed to have any significant performance impact.

Copy link
Member Author

@StefanKarpinski StefanKarpinski Sep 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be type unstable but since the introduction of SSAIR the compiler doesn't care about the reuse of variable names at all (that's basically what the SS part means: single static assignment so reassigning amounts to just assigning a different variable). It only matters if the same "slot" in a basic block can have different types, e.g. in the loop body below. Even then the union splitting can deal with it fairly often.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this explanation, that's very good to know, it allows not bothering with this kind of gymnastic!

@JeffBezanson JeffBezanson added the needs tests Unit tests are required for this change label Sep 16, 2018
Alternative based on #29187

Tests from rforquet's PR linked above.
@StefanKarpinski StefanKarpinski merged commit 16516b5 into master Sep 17, 2018
@StefanKarpinski StefanKarpinski deleted the sk/digits-unsigned branch September 17, 2018 12:51
@StefanKarpinski StefanKarpinski added backport pending 1.0 bugfix This change fixes an existing bug maths Mathematical functions and removed needs tests Unit tests are required for this change labels Sep 18, 2018
KristofferC pushed a commit that referenced this pull request Sep 30, 2018
Alternative based on #29187

Tests from rforquet's PR linked above.

(cherry picked from commit 16516b5)
KristofferC pushed a commit that referenced this pull request Feb 11, 2019
Alternative based on #29187

Tests from rforquet's PR linked above.

(cherry picked from commit 16516b5)
KristofferC pushed a commit that referenced this pull request Feb 20, 2020
Alternative based on #29187

Tests from rforquet's PR linked above.

(cherry picked from commit 16516b5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants