Skip to content

Fix Integer.extended_gcd/2 returning negative GCD for zero base cases#15163

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix/extended-gcd-negative-zero-base-cases
Mar 10, 2026
Merged

Fix Integer.extended_gcd/2 returning negative GCD for zero base cases#15163
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix/extended-gcd-negative-zero-base-cases

Conversation

@pnezis
Copy link
Copy Markdown
Contributor

@pnezis pnezis commented Mar 9, 2026

When one argument is 0 and the other is negative, extended_gcd/2 was returning a negative GCD, violating both the spec (which declares non_neg_integer) and consistency with gcd/2.

iex(12)> Integer.extended_gcd(-10, 0)
{-10, 1, 0}

When one argument is 0 and the other is negative, `extended_gcd/2`
was returning a negative GCD, violating both the @SPEC (which
declares `non_neg_integer`) and consistency with `gcd/2`.
@josevalim josevalim merged commit 6f9afad into elixir-lang:main Mar 10, 2026
15 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants