mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
commit
4570ccd0d5
2 changed files with 32 additions and 0 deletions
13
decimal.go
13
decimal.go
|
@ -413,6 +413,19 @@ func (d Decimal) Equals(d2 Decimal) bool {
|
|||
return d.Equal(d2)
|
||||
}
|
||||
|
||||
// Sign returns:
|
||||
//
|
||||
// -1 if d < 0
|
||||
// 0 if d == 0
|
||||
// +1 if d > 0
|
||||
//
|
||||
func (d Decimal) Sign() int {
|
||||
if d.value == nil {
|
||||
return 0
|
||||
}
|
||||
return d.value.Sign()
|
||||
}
|
||||
|
||||
// Exponent returns the exponent, or scale component of the decimal.
|
||||
func (d Decimal) Exponent() int32 {
|
||||
return d.exp
|
||||
|
|
|
@ -536,6 +536,9 @@ func TestDecimal_Uninitialized(t *testing.T) {
|
|||
if a.Cmp(b) != 0 {
|
||||
t.Errorf("a != b")
|
||||
}
|
||||
if a.Sign() != 0 {
|
||||
t.Errorf("a.Sign() != 0")
|
||||
}
|
||||
if a.Exponent() != 0 {
|
||||
t.Errorf("a.Exponent() != 0")
|
||||
}
|
||||
|
@ -1330,6 +1333,22 @@ func TestPow(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDecimal_Sign(t *testing.T) {
|
||||
if Zero.Sign() != 0 {
|
||||
t.Errorf("%q should have sign 0", Zero)
|
||||
}
|
||||
|
||||
one := New(1, 0)
|
||||
if one.Sign() != 1 {
|
||||
t.Errorf("%q should have sign 1", one)
|
||||
}
|
||||
|
||||
mone := New(-1, 0)
|
||||
if mone.Sign() != -1 {
|
||||
t.Errorf("%q should have sign -1", mone)
|
||||
}
|
||||
}
|
||||
|
||||
func didPanic(f func()) bool {
|
||||
ret := false
|
||||
func() {
|
||||
|
|
Loading…
Reference in a new issue