diff --git a/math/math_test.go b/math/math_test.go index 094099e..eba73df 100644 --- a/math/math_test.go +++ b/math/math_test.go @@ -3,7 +3,9 @@ package math_test import ( "testing" + "github.com/ericlagergren/decimal" "github.com/ericlagergren/decimal/internal/test" + "github.com/ericlagergren/decimal/math" ) func TestExp(t *testing.T) { test.Exp.Test(t) } @@ -11,3 +13,16 @@ func TestLog(t *testing.T) { test.Log.Test(t) } func TestLog10(t *testing.T) { test.Log10.Test(t) } func TestPow(t *testing.T) { test.Pow.Test(t) } func TestSqrt(t *testing.T) { test.Sqrt.Test(t) } + +func TestIssue146(t *testing.T) { + one := decimal.New(1, 0) + for i := int64(0); i < 10; i++ { + n := decimal.New(i, 1) + firstPow := math.Pow(new(decimal.Big), n, one) + if n.Cmp(firstPow) != 0 { + t.Errorf("%v^1 != %v", n, firstPow) + } else { + t.Logf("%v^1 == %v", n, firstPow) + } + } +} diff --git a/math/pow.go b/math/pow.go index 394e55a..0c2ce14 100644 --- a/math/pow.go +++ b/math/pow.go @@ -54,7 +54,7 @@ func Pow(z, x, y *decimal.Big) *decimal.Big { return z.SetUint64(1) } - if x.Cmp(ptFive) == 0 { + if y.Cmp(ptFive) == 0 { // x ** 0.5 = sqrt(x) return Sqrt(z, x) }