Skip to content

Conversation

adienes
Copy link
Member

@adienes adienes commented Sep 28, 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

@adienes adienes added maths Mathematical functions bugfix This change fixes an existing bug backport 1.10 Change should be backported to the 1.10 release backport 1.12 Change should be backported to release-1.12 labels Sep 28, 2025
@adienes
Copy link
Member Author

adienes commented Sep 30, 2025

this one I think is basically "typo" territory and was clearly the original intention of the implementation

@KristofferC KristofferC mentioned this pull request Sep 30, 2025
31 tasks
@adienes adienes added merge me PR is reviewed. Merge when all tests are passing and removed merge me PR is reviewed. Merge when all tests are passing labels Sep 30, 2025
@adienes
Copy link
Member Author

adienes commented Sep 30, 2025

I'll leave this up for a few days and merge by EOW if no protest

@oscardssmith oscardssmith merged commit bb3be0d into JuliaLang:master Sep 30, 2025
9 checks passed
@oscardssmith
Copy link
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.12 Change should be backported to release-1.12 bugfix This change fixes an existing bug maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants