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
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue