replace log.Fatal with cobra.CheckErr
This commit is contained in:
10
cmd/crt.go
10
cmd/crt.go
@@ -18,7 +18,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/big"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -30,7 +29,7 @@ var moduli []string
|
||||
|
||||
func crt(cmd *cobra.Command, args []string) {
|
||||
if len(remainders) != len(moduli) {
|
||||
log.Fatal("number of remainders and moduli do not match")
|
||||
cobra.CheckErr("number of remainders and moduli do not match")
|
||||
}
|
||||
|
||||
ns := make([]*big.Int, len(moduli))
|
||||
@@ -39,18 +38,19 @@ func crt(cmd *cobra.Command, args []string) {
|
||||
var ok bool
|
||||
ns[i], ok = new(big.Int).SetString(moduli[i], 10)
|
||||
if !ok {
|
||||
log.Fatal("invalid input " + moduli[i])
|
||||
cobra.CheckErr("invalid input " + moduli[i])
|
||||
}
|
||||
|
||||
rs[i], ok = new(big.Int).SetString(remainders[i], 10)
|
||||
if !ok {
|
||||
log.Fatal("invalid input " + remainders[i])
|
||||
cobra.CheckErr("invalid input " + remainders[i])
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: support non-pairwise coprime moduli
|
||||
if !lib.ArePairwiseCoprime(ns) {
|
||||
log.Fatalf("moduli %v are not pairwise coprime", moduli)
|
||||
err := fmt.Errorf("moduli %v are not pairwise coprime", moduli)
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
|
||||
x, N := lib.CRTSolution(rs, ns)
|
||||
|
||||
Reference in New Issue
Block a user