Skip to content

Commit

Permalink
Improve go report cards score (#174)
Browse files Browse the repository at this point in the history
* Improve go report cards score
  • Loading branch information
mwoss authored Apr 27, 2020
1 parent 1884f45 commit c939845
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
28 changes: 12 additions & 16 deletions decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func TestRequireFromStringErrs(t *testing.T) {
err = recover()
}()

d = RequireFromString(s)
RequireFromString(s)
}(d)

if err == nil {
Expand Down Expand Up @@ -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})
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2146,7 +2146,7 @@ func TestNullDecimal_Scan(t *testing.T) {
}
}

dbvalue := float64(54.33)
dbvalue := 54.33
expected := NewFromFloat(dbvalue)

err = a.Scan(dbvalue)
Expand Down

0 comments on commit c939845

Please sign in to comment.