diff --git a/condition.go b/condition.go index 2c6e034..8b05089 100644 --- a/condition.go +++ b/condition.go @@ -15,9 +15,9 @@ package apd import ( + "errors" + "fmt" "strings" - - "github.com/pkg/errors" ) // Condition holds condition flags. @@ -143,7 +143,7 @@ func (r Condition) String() string { case Clamped: s = "clamped" default: - panic(errors.Errorf("unknown condition %d", i)) + panic(fmt.Errorf("unknown condition %d", i)) } names = append(names, s) } diff --git a/context.go b/context.go index acd353f..9d9e2d8 100644 --- a/context.go +++ b/context.go @@ -15,9 +15,9 @@ package apd import ( + "errors" + "fmt" "math" - - "github.com/pkg/errors" ) // Context maintains options for Decimal operations. It can safely be used @@ -116,7 +116,7 @@ func (c *Context) setAsNaN(d *Decimal, x, y *Decimal) (Condition, error) { } else if y != nil && y.Form == NaN { nan = y } else { - return 0, errors.Errorf("no NaN value found; was shouldSetAsNaN called?") + return 0, errors.New("no NaN value found; was shouldSetAsNaN called?") } d.Set(nan) var res Condition @@ -149,7 +149,7 @@ func (c *Context) add(d, x, y *Decimal, subtract bool) (Condition, error) { var tmp BigInt a, b, s, err := upscale(x, y, &tmp) if err != nil { - return 0, errors.Wrap(err, "add") + return 0, fmt.Errorf("add: %w", err) } d.Negative = xn if xn == yn { @@ -379,7 +379,7 @@ func (c *Context) QuoInteger(d, x, y *Decimal) (Condition, error) { var tmp BigInt a, b, _, err := upscale(x, y, &tmp) if err != nil { - return 0, errors.Wrap(err, "QuoInteger") + return 0, fmt.Errorf("QuoInteger: %w", err) } d.Coeff.Quo(a, b) d.Form = Finite @@ -421,7 +421,7 @@ func (c *Context) Rem(d, x, y *Decimal) (Condition, error) { var tmp1 BigInt a, b, s, err := upscale(x, y, &tmp1) if err != nil { - return 0, errors.Wrap(err, "Rem") + return 0, fmt.Errorf("Rem: %w", err) } var tmp2 BigInt tmp2.QuoRem(a, b, &d.Coeff) @@ -858,7 +858,7 @@ func (c *Context) Log10(d, x *Decimal) (Condition, error) { var z Decimal _, err := nc.Ln(&z, x) if err != nil { - return 0, errors.Wrap(err, "ln") + return 0, fmt.Errorf("ln: %w", err) } nc.Precision = c.Precision @@ -942,7 +942,7 @@ func (c *Context) Exp(d, x *Decimal) (Condition, error) { nc := c.WithPrecision(cp) nc.Rounding = RoundHalfEven if _, err := nc.Quo(&r, x, &k); err != nil { - return 0, errors.Wrap(err, "Quo") + return 0, fmt.Errorf("Quo: %w", err) } var ra Decimal ra.Abs(&r) @@ -951,7 +951,7 @@ func (c *Context) Exp(d, x *Decimal) (Condition, error) { // Stage 3 rf, err := ra.Float64() if err != nil { - return 0, errors.Wrap(err, "r.Float64") + return 0, fmt.Errorf("r.Float64: %w", err) } pf := float64(p) nf := math.Ceil((1.435*pf - 1.182) / math.Log10(pf/rf)) @@ -983,11 +983,11 @@ func (c *Context) Exp(d, x *Decimal) (Condition, error) { var tmpE BigInt ki, err := exp10(int64(t), &tmpE) if err != nil { - return 0, errors.Wrap(err, "ki") + return 0, fmt.Errorf("ki: %w", err) } ires, err := nc.integerPower(d, &sum, ki) if err != nil { - return 0, errors.Wrap(err, "integer power") + return 0, fmt.Errorf("integer power: %w", err) } res |= ires nc.Precision = c.Precision diff --git a/decimal.go b/decimal.go index 493b46e..b365372 100644 --- a/decimal.go +++ b/decimal.go @@ -15,12 +15,13 @@ package apd import ( + "errors" + "fmt" "strconv" "strings" "unsafe" "database/sql/driver" - "github.com/pkg/errors" ) // Decimal is an arbitrary-precision decimal. Its value is: @@ -113,7 +114,7 @@ func (d *Decimal) setString(c *Context, s string) (Condition, error) { // Until there are no parse errors, leave as NaN. d.Form = NaN if strings.HasPrefix(s, "-") || strings.HasPrefix(s, "+") { - return 0, errors.Errorf("could not parse: %s", orig) + return 0, fmt.Errorf("could not parse: %s", orig) } switch s { case "infinity", "inf": @@ -135,7 +136,7 @@ func (d *Decimal) setString(c *Context, s string) (Condition, error) { // We ignore these digits, but must verify them. _, err := strconv.ParseUint(s, 10, 64) if err != nil { - return 0, errors.Wrapf(err, "parse payload: %s", s) + return 0, fmt.Errorf("parse payload: %s: %w", s, err) } } return 0, nil @@ -145,7 +146,7 @@ func (d *Decimal) setString(c *Context, s string) (Condition, error) { if i := strings.IndexByte(s, 'e'); i >= 0 { exp, err := strconv.ParseInt(s[i+1:], 10, 32) if err != nil { - return 0, errors.Wrapf(err, "parse exponent: %s", s[i+1:]) + return 0, fmt.Errorf("parse exponent: %s: %w", s[i+1:], err) } exps = append(exps, exp) s = s[:i] @@ -156,7 +157,7 @@ func (d *Decimal) setString(c *Context, s string) (Condition, error) { s = s[:i] + s[i+1:] } if _, ok := d.Coeff.SetString(s, 10); !ok { - return 0, errors.Errorf("parse mantissa: %s", s) + return 0, fmt.Errorf("parse mantissa: %s", s) } // No parse errors, can now flag as finite. d.Form = Finite @@ -248,19 +249,19 @@ func (d *Decimal) SetFloat64(f float64) (*Decimal, error) { // int64, an error is returned. func (d *Decimal) Int64() (int64, error) { if d.Form != Finite { - return 0, errors.Errorf("%s is not finite", d.String()) + return 0, fmt.Errorf("%s is not finite", d.String()) } var integ, frac Decimal d.Modf(&integ, &frac) if !frac.IsZero() { - return 0, errors.Errorf("%s: has fractional part", d.String()) + return 0, fmt.Errorf("%s: has fractional part", d.String()) } var ed ErrDecimal if integ.Cmp(decimalMaxInt64) > 0 { - return 0, errors.Errorf("%s: greater than max int64", d.String()) + return 0, fmt.Errorf("%s: greater than max int64", d.String()) } if integ.Cmp(decimalMinInt64) < 0 { - return 0, errors.Errorf("%s: less than min int64", d.String()) + return 0, fmt.Errorf("%s: less than min int64", d.String()) } if err := ed.Err(); err != nil { return 0, err @@ -781,7 +782,7 @@ func (d *Decimal) Scan(src interface{}) error { _, err := d.SetFloat64(src) return err default: - return errors.Errorf("could not convert %T to Decimal", src) + return fmt.Errorf("could not convert %T to Decimal", src) } } diff --git a/go.mod b/go.mod index ac9e498..33e0f92 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/cockroachdb/apd/v3 -go 1.13 +go 1.17 -require github.com/pkg/errors v0.8.0 +require github.com/lib/pq v1.10.7 diff --git a/go.sum b/go.sum index 3dfe462..e9190c6 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= +github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= diff --git a/loop.go b/loop.go index 210210d..78b93de 100644 --- a/loop.go +++ b/loop.go @@ -7,9 +7,8 @@ package apd import ( + "fmt" "math" - - "github.com/pkg/errors" ) type loop struct { @@ -79,7 +78,7 @@ func (l *loop) done(z *Decimal) (bool, error) { } l.i++ if l.i == l.maxIterations { - return false, errors.Errorf( + return false, fmt.Errorf( "%s %s: did not converge after %d iterations; prev,last result %s,%s delta %s precision: %d", l.name, l.arg.String(), l.maxIterations, z.String(), l.prevZ.String(), l.delta.String(), l.precision, )