mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Add Copy func (#123)
* Add Copy method Co-authored-by: habuvo <Sin90is0>
This commit is contained in:
parent
46544472a5
commit
013e52d4e9
2 changed files with 32 additions and 3 deletions
13
decimal.go
13
decimal.go
|
@ -1755,7 +1755,7 @@ func (d Decimal) Sin() Decimal {
|
||||||
sign = !sign
|
sign = !sign
|
||||||
j -= 4
|
j -= 4
|
||||||
}
|
}
|
||||||
z := d.Sub(y.Mul(PI4A)).Sub(y.Mul(PI4B)).Sub(y.Mul(PI4C)) // Extended precision modular arithmetic
|
z := d.Sub(y.Mul(PI4A)).Sub(y.Mul(PI4B)).Sub(y.Mul(PI4C)) // Extended precision modular arithmetic
|
||||||
zz := z.Mul(z)
|
zz := z.Mul(z)
|
||||||
|
|
||||||
if j == 1 || j == 2 {
|
if j == 1 || j == 2 {
|
||||||
|
@ -1886,3 +1886,14 @@ func (d Decimal) Tan() Decimal {
|
||||||
}
|
}
|
||||||
return y
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3288,3 +3288,21 @@ func ExampleNewFromFloat() {
|
||||||
//0.123123123123123
|
//0.123123123123123
|
||||||
//-10000000000000
|
//-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