From c939845a686f85525ee0074a65e8a10602c0478f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Wo=C5=9B?= Date: Mon, 27 Apr 2020 08:03:21 +0200 Subject: [PATCH] Improve go report cards score (#174) * Improve go report cards score --- decimal.go | 28 ++++++++++++---------------- decimal_test.go | 10 +++++----- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/decimal.go b/decimal.go index 6a986b2e..4badeb59 100644 --- a/decimal.go +++ b/decimal.go @@ -55,9 +55,6 @@ var MarshalJSONWithoutQuotes = false // Zero constant, to make computations faster. var Zero = New(0, 1) -// fiveDec used in Cash Rounding -var fiveDec = New(5, 0) - var zeroInt = big.NewInt(0) var oneInt = big.NewInt(1) var twoInt = big.NewInt(2) @@ -296,10 +293,9 @@ func NewFromFloatWithExponent(value float64, exp int32) Decimal { // specials if mant == 0 { return Decimal{} - } else { - // subnormal - exp2++ } + // subnormal + exp2++ } else { // normal mant |= 1 << 52 @@ -947,13 +943,13 @@ func (d *Decimal) UnmarshalJSON(decimalBytes []byte) error { str, err := unquoteIfQuoted(decimalBytes) if err != nil { - return fmt.Errorf("Error decoding string '%s': %s", decimalBytes, err) + return fmt.Errorf("error decoding string '%s': %s", decimalBytes, err) } decimal, err := NewFromString(str) *d = decimal if err != nil { - return fmt.Errorf("Error decoding string '%s': %s", str, err) + return fmt.Errorf("error decoding string '%s': %s", str, err) } return nil } @@ -1041,7 +1037,7 @@ func (d *Decimal) UnmarshalText(text []byte) error { dec, err := NewFromString(str) *d = dec if err != nil { - return fmt.Errorf("Error decoding string '%s': %s", str, err) + return fmt.Errorf("error decoding string '%s': %s", str, err) } return nil @@ -1203,7 +1199,7 @@ func unquoteIfQuoted(value interface{}) (string, error) { case []byte: bytes = v default: - return "", fmt.Errorf("Could not convert value '%+v' to byte array of type '%T'", + return "", fmt.Errorf("could not convert value '%+v' to byte array of type '%T'", value, value) } @@ -1260,14 +1256,14 @@ func (d NullDecimal) MarshalJSON() ([]byte, error) { // Trig functions // Atan returns the arctangent, in radians, of x. -func (x Decimal) Atan() Decimal { - if x.Equal(NewFromFloat(0.0)) { - return x +func (d Decimal) Atan() Decimal { + if d.Equal(NewFromFloat(0.0)) { + return d } - if x.GreaterThan(NewFromFloat(0.0)) { - return x.satan() + if d.GreaterThan(NewFromFloat(0.0)) { + return d.satan() } - return x.Neg().satan().Neg() + return d.Neg().satan().Neg() } func (d Decimal) xatan() Decimal { diff --git a/decimal_test.go b/decimal_test.go index 98417201..488d4055 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -358,7 +358,7 @@ func TestRequireFromStringErrs(t *testing.T) { err = recover() }() - d = RequireFromString(s) + RequireFromString(s) }(d) if err == nil { @@ -1404,8 +1404,8 @@ func createDivTestCases() []DivTestCase { for _, v2 := range a { // 11, even if 0 is skipped sign1 := New(int64(s), 0) sign2 := New(int64(s2), 0) - d := sign1.Mul(New(int64(v1), int32(e1))) - d2 := sign2.Mul(New(int64(v2), int32(e2))) + d := sign1.Mul(New(int64(v1), e1)) + d2 := sign2.Mul(New(int64(v2), e2)) res = append(res, DivTestCase{d, d2, prec}) } } @@ -1842,7 +1842,7 @@ func TestDecimal_Scan(t *testing.T) { // in normal operations the db driver (sqlite at least) // will return an int64 if you specified a numeric format a := Decimal{} - dbvalue := float64(54.33) + dbvalue := 54.33 expected := NewFromFloat(dbvalue) err := a.Scan(dbvalue) @@ -2146,7 +2146,7 @@ func TestNullDecimal_Scan(t *testing.T) { } } - dbvalue := float64(54.33) + dbvalue := 54.33 expected := NewFromFloat(dbvalue) err = a.Scan(dbvalue)