From 58985c9504eca6cec9f1348df67b39033d29f966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Thu, 11 Aug 2022 15:32:51 +0800 Subject: [PATCH] - update operation --- big_operation.go | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ version.go | 2 +- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/big_operation.go b/big_operation.go index a01c05a..3aa3f47 100644 --- a/big_operation.go +++ b/big_operation.go @@ -7,6 +7,27 @@ func (d Decimal) Add(d2 Decimal) Decimal { return mul } +// AddFloat 加 +func (d Decimal) AddFloat(d2 float64) Decimal { + mul := New() + mul.floatValue.Add(d.floatValue, NewFloat(d2).floatValue) + return mul +} + +// AddInt 加 +func (d Decimal) AddInt(d2 int64) Decimal { + mul := New() + mul.floatValue.Add(d.floatValue, NewInt(d2).floatValue) + return mul +} + +// AddString 加 +func (d Decimal) AddString(d2 string) Decimal { + mul := New() + mul.floatValue.Add(d.floatValue, NewString(d2).floatValue) + return mul +} + // Sub 减 (d-d2) func (d Decimal) Sub(d2 Decimal) Decimal { mul := New() @@ -14,6 +35,27 @@ func (d Decimal) Sub(d2 Decimal) Decimal { return mul } +// SubFloat 减 +func (d Decimal) SubFloat(d2 float64) Decimal { + mul := New() + mul.floatValue.Sub(d.floatValue, NewFloat(d2).floatValue) + return mul +} + +// SubInt 减 +func (d Decimal) SubInt(d2 int64) Decimal { + mul := New() + mul.floatValue.Sub(d.floatValue, NewInt(d2).floatValue) + return mul +} + +// SubString 减 +func (d Decimal) SubString(d2 string) Decimal { + mul := New() + mul.floatValue.Sub(d.floatValue, NewString(d2).floatValue) + return mul +} + // Mul 乘 (d*d2) func (d Decimal) Mul(d2 Decimal) Decimal { mul := New() @@ -21,9 +63,51 @@ func (d Decimal) Mul(d2 Decimal) Decimal { return mul } +// MulFloat 乘 +func (d Decimal) MulFloat(d2 float64) Decimal { + mul := New() + mul.floatValue.Mul(d.floatValue, NewFloat(d2).floatValue) + return mul +} + +// MulInt 乘 +func (d Decimal) MulInt(d2 int64) Decimal { + mul := New() + mul.floatValue.Mul(d.floatValue, NewInt(d2).floatValue) + return mul +} + +// MulString 乘 +func (d Decimal) MulString(d2 string) Decimal { + mul := New() + mul.floatValue.Mul(d.floatValue, NewString(d2).floatValue) + return mul +} + // Quo 除 (d/d2) func (d Decimal) Quo(d2 Decimal) Decimal { mul := New() mul.floatValue.Quo(d.floatValue, d2.floatValue) return mul } + +// QuoFloat 除 +func (d Decimal) QuoFloat(d2 float64) Decimal { + mul := New() + mul.floatValue.Quo(d.floatValue, NewFloat(d2).floatValue) + return mul +} + +// QuoInt 除 +func (d Decimal) QuoInt(d2 int64) Decimal { + mul := New() + mul.floatValue.Quo(d.floatValue, NewInt(d2).floatValue) + return mul +} + +// QuoString 除 +func (d Decimal) QuoString(d2 string) Decimal { + mul := New() + mul.floatValue.Quo(d.floatValue, NewString(d2).floatValue) + return mul +} diff --git a/version.go b/version.go index 7876fb0..ed0afb0 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package godecimal -const Version = "1.0.4" +const Version = "1.0.5"