break out bezout computations to separate function

This commit is contained in:
filifa 2025-08-11 23:36:54 -04:00
parent c6b9c1586e
commit c537b3dc71
1 changed files with 12 additions and 11 deletions

View File

@ -26,6 +26,16 @@ import (
var extended bool var extended bool
func computeBezouts(bezouts []big.Int, x, y *big.Int) {
for i, c := range bezouts {
if i == len(bezouts)-1 {
bezouts[i].Set(y)
} else {
bezouts[i].Mul(&c, x)
}
}
}
func gcd(cmd *cobra.Command, args []string) { func gcd(cmd *cobra.Command, args []string) {
x := new(big.Int) x := new(big.Int)
y := new(big.Int) y := new(big.Int)
@ -42,17 +52,8 @@ func gcd(cmd *cobra.Command, args []string) {
z.GCD(x, y, z, w) z.GCD(x, y, z, w)
if !extended { if extended {
continue computeBezouts(bezouts[:i+1], x, y)
}
for j, c := range bezouts {
if j == i {
bezouts[j].Set(y)
} else {
bezouts[j].Mul(&c, x)
}
} }
} }