break out bezout computations to separate function
This commit is contained in:
parent
c6b9c1586e
commit
c537b3dc71
23
cmd/gcd.go
23
cmd/gcd.go
|
|
@ -26,6 +26,16 @@ import (
|
|||
|
||||
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) {
|
||||
x := new(big.Int)
|
||||
y := new(big.Int)
|
||||
|
|
@ -42,17 +52,8 @@ func gcd(cmd *cobra.Command, args []string) {
|
|||
|
||||
z.GCD(x, y, z, w)
|
||||
|
||||
if !extended {
|
||||
continue
|
||||
}
|
||||
|
||||
for j, c := range bezouts {
|
||||
if j == i {
|
||||
bezouts[j].Set(y)
|
||||
} else {
|
||||
bezouts[j].Mul(&c, x)
|
||||
}
|
||||
|
||||
if extended {
|
||||
computeBezouts(bezouts[:i+1], x, y)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue