From a4bb9ec23b849038f37cdc398c19181e8e15e7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Mon, 6 May 2019 05:35:13 -0400 Subject: [PATCH] Update arithmetic.jl --- src/arithmetic.jl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index e729cc5..6d2f322 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -43,4 +43,28 @@ end # Division /(x::Decimal, y::Decimal) = x * inv(y) -# TODO exponentiation +# Exponentiation, please test + +function ^(x::Decimal, y::Decimal) + #(-1.23)^(something) code to catch errors prior to the routine + x.s == 1 && begin + (y.q < 0 && throw(DomainError(y),"Exponentiation yielding a complex result requires a complex argument.")) + end + y.s == 1 && (return ^(inv(x),-y)) + y.q < 0 && (return Decimal(BigFloat(x)^BigFloat(y))) #add correction to precision, its too much + + if iseven(y.c) #squared number + zs = 0 + else + if x.s == 0 + zs =0 + else + zs = 1 + end + end + + zc = x.c^((y.c)*(10^y.q)) + zq = (x.q)*((y.c)*(10^y.q)) + return Decimal(zs,zc,zq) + +end