Exponentiation in Julia

Hi Julia community,
I am a new Julia user. Like what I see till now but with sometimes its head twisting.
For example today I saw something and I wanted to know the difference between

(-(0.5/1))^1.5

vs

-(0.5/1)^1.5

First one gives me error:

ERROR: DomainError with -0.5:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.
Stacktrace:
 [1] throw_exp_domainerror(::Float64) at .\math.jl:37
 [2] ^(::Float64, ::Float64) at .\math.jl:872
 [3] top-level scope at REPL[9]:1

and the second code gives me answer: -0.35355339059327373

I was wondering what I am doing wrong in the first example of (-(0.5/1))^1.5 that its expecting a complex number?

You are raising a negative number to the power 3/2, and that’s just not something you can do without complex numbers. It is the same as trying to take the square root of a negative number.

2 Likes

And the second one was calculating -(0.5^1.5)

2 Likes

Thanks everyone for answering. Searching around the forum I also found this thread which is useful.

Complex numbers