Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operations: exponentiation #2

Open
tinybike opened this issue Jul 6, 2014 · 1 comment
Open

Operations: exponentiation #2

tinybike opened this issue Jul 6, 2014 · 1 comment
Assignees

Comments

@tinybike
Copy link
Member

tinybike commented Jul 6, 2014

No description provided.

@tinybike tinybike self-assigned this Jul 6, 2014
@longemen3000
Copy link

longemen3000 commented May 6, 2019

this works in a way, it takes care of all irrational cases by going into bigfloat, if not, then the Decimal fields
are calculated manually

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants