mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
Reformat code base and update decimal copy docs (#249)
This commit is contained in:
parent
3259e0a2de
commit
283b007e5f
2 changed files with 29 additions and 33 deletions
20
decimal.go
20
decimal.go
|
@ -414,6 +414,15 @@ func NewFromFloatWithExponent(value float64, exp int32) Decimal {
|
|||
}
|
||||
}
|
||||
|
||||
// Copy returns a copy of decimal with the same value and exponent, but a different pointer to value.
|
||||
func (d Decimal) Copy() Decimal {
|
||||
d.ensureInitialized()
|
||||
return Decimal{
|
||||
value: &(*d.value),
|
||||
exp: d.exp,
|
||||
}
|
||||
}
|
||||
|
||||
// rescale returns a rescaled version of the decimal. Returned
|
||||
// decimal may be less precise if the given exponent is bigger
|
||||
// than the initial exponent of the Decimal.
|
||||
|
@ -1893,14 +1902,3 @@ func (d Decimal) Tan() Decimal {
|
|||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// Copy makes instance of d with same value and different pointer.
|
||||
func (d Decimal) Copy() Decimal {
|
||||
d.ensureInitialized()
|
||||
return Decimal{
|
||||
value: &(*d.value),
|
||||
exp: d.exp,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -556,6 +556,22 @@ func TestNewFromBigIntWithExponent(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCopy(t *testing.T) {
|
||||
origin := New(1, 0)
|
||||
cpy := origin.Copy()
|
||||
|
||||
if cpy.Cmp(origin) != 0 {
|
||||
t.Error("expecting copy and origin to be equals, but they are not")
|
||||
}
|
||||
|
||||
//change value
|
||||
cpy = cpy.Add(New(1, 0))
|
||||
|
||||
if cpy.Cmp(origin) == 0 {
|
||||
t.Error("expecting copy and origin to have different values, but they are equal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSON(t *testing.T) {
|
||||
for _, x := range testTable {
|
||||
s := x.short
|
||||
|
@ -3300,21 +3316,3 @@ func ExampleNewFromFloat() {
|
|||
//0.123123123123123
|
||||
//-10000000000000
|
||||
}
|
||||
|
||||
//For Copy
|
||||
func TestCopy(t *testing.T) {
|
||||
origin := New(1, 0)
|
||||
cpy := origin.Copy()
|
||||
|
||||
if cpy.Cmp(origin) != 0 {
|
||||
t.Error("copy and origin not equal")
|
||||
}
|
||||
|
||||
//change value
|
||||
cpy = cpy.Add(New(1, 0))
|
||||
|
||||
if cpy.Cmp(origin) == 0 {
|
||||
t.Error("copy and origin are equal but expected not")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue