Can you wrap both operands in the attempt without the variable in parenthesis and tell me if the output changes? Not at my computer right now. Betting it has something to do with operator precedence. Your first case shouldn’t even work because you’re taking the root of a negative number.
Fractional exponents can also be expressed using a root.
x^(3/2) == x^1.5 == sqrt(x^3)
Since you have a decimal number, a simplified case like above is easier to understand.
When x is negative, an odd power of it is also negative. Taking the even root of that then doesn’t work.
—
Yes, it looks like applying the power when that number isn’t negative and then negating the result produces what you’re seeing. For some reason the subtraction operator has a lower precedence than the exponentiation operator.
Basically what is happening is that the computer thinks you mean
print(-1 * (0.53220192342997 ^ 1.45))
This will give you an answer because you are taking the root of a positive number, all of your calculations are positive, and then you are making it negative at the end.
Whereas when you store -0.53220192342997 as a variable, it leaves no ambiguity, and therefore you are trying to take the root of a negative number.
print((-0.53220192342997) ^ 1.45)
The way to make it work with the variable would just be to imitate what is happening in the first case, ie:
Do all of your calculations with positive numbers
Multiply by -1 after the calculation has been completed
local num = 0.53220192342997
local pow = 1.45
local ans = num ^ pow
ans = ans * -1
print(ans)
Raising a negative number to a power that’s not a whole number is likely to produce NaN, which is explained above. Storing it in a variable will not change that.
The problem in this thread was that - is evaluated after ^, resulting it OPs math to appear to work. The OP needs to do this operation on math.abs of the number, then multiply by the number’s math.sign to avoid the NaN issue.