Improve go report cards score (#174)

* Improve go report cards score
This commit is contained in:
Mateusz Woś 2020-04-27 08:03:21 +02:00 committed by GitHub
parent 1884f454f8
commit c939845a68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 21 deletions

View file

@ -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++
}
} 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 {

View file

@ -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)