diff --git a/decimal.go b/decimal.go index c614ea7..5982f81 100644 --- a/decimal.go +++ b/decimal.go @@ -418,7 +418,7 @@ func NewFromFloatWithExponent(value float64, exp int32) Decimal { func (d Decimal) Copy() Decimal { d.ensureInitialized() return Decimal{ - value: &(*d.value), + value: new(big.Int).Set(d.value), exp: d.exp, } } diff --git a/decimal_test.go b/decimal_test.go index 2b3a99e..c6d2b24 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -560,6 +560,10 @@ func TestCopy(t *testing.T) { origin := New(1, 0) cpy := origin.Copy() + if origin.value == cpy.value { + t.Error("expecting copy and origin to have different value pointers") + } + if cpy.Cmp(origin) != 0 { t.Error("expecting copy and origin to be equals, but they are not") }