fix powermod correctness on unsigned power of half typemax#59680
Merged
oscardssmith merged 2 commits intoJuliaLang:masterfrom Sep 30, 2025
Merged
fix powermod correctness on unsigned power of half typemax#59680oscardssmith merged 2 commits intoJuliaLang:masterfrom
powermod correctness on unsigned power of half typemax#59680oscardssmith merged 2 commits intoJuliaLang:masterfrom
Conversation
Member
Author
|
this one I think is basically "typo" territory and was clearly the original intention of the implementation |
Member
Author
|
I'll leave this up for a few days and merge by EOW if no protest |
Member
|
Thanks! |
KristofferC
pushed a commit
that referenced
this pull request
Oct 4, 2025
the comment claims: > When the concrete type of p is signed and has the lowest value, > `p != 0 && p == -p` is equivalent to `p == typemin(typeof(p))` this is true, but fails to consider that `p == -p` is also true when `p = div(typemax(UInt), 2) + 1`, and that `p` is not necessarily signed leading to incorrect results on inputs like ``` julia> powermod(0x03, 0x80, 0x07) 0x01 ``` which should be `0x02` (cherry picked from commit bb3be0d)
KristofferC
pushed a commit
that referenced
this pull request
Oct 12, 2025
the comment claims: > When the concrete type of p is signed and has the lowest value, > `p != 0 && p == -p` is equivalent to `p == typemin(typeof(p))` this is true, but fails to consider that `p == -p` is also true when `p = div(typemax(UInt), 2) + 1`, and that `p` is not necessarily signed leading to incorrect results on inputs like ``` julia> powermod(0x03, 0x80, 0x07) 0x01 ``` which should be `0x02` (cherry picked from commit bb3be0d)
Merged
Merged
DilumAluthge
pushed a commit
that referenced
this pull request
Jan 19, 2026
the comment claims: > When the concrete type of p is signed and has the lowest value, > `p != 0 && p == -p` is equivalent to `p == typemin(typeof(p))` this is true, but fails to consider that `p == -p` is also true when `p = div(typemax(UInt), 2) + 1`, and that `p` is not necessarily signed leading to incorrect results on inputs like ``` julia> powermod(0x03, 0x80, 0x07) 0x01 ``` which should be `0x02` (cherry picked from commit bb3be0d)
71 tasks
DilumAluthge
pushed a commit
that referenced
this pull request
Jan 20, 2026
the comment claims: > When the concrete type of p is signed and has the lowest value, > `p != 0 && p == -p` is equivalent to `p == typemin(typeof(p))` this is true, but fails to consider that `p == -p` is also true when `p = div(typemax(UInt), 2) + 1`, and that `p` is not necessarily signed leading to incorrect results on inputs like ``` julia> powermod(0x03, 0x80, 0x07) 0x01 ``` which should be `0x02` (cherry picked from commit bb3be0d)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
the comment claims:
this is true, but fails to consider that
p == -pis also true whenp = div(typemax(UInt), 2) + 1, and thatpis not necessarily signedleading to incorrect results on inputs like
which should be
0x02