Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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