So when I do

```
print(-3^2)
= -9
```

and when I do

```
print((-3)^2)
= 9
```

I dont understand, wouldn’t the first one also be postive as a negative number times a negative number is positive? What difference does the brackets make?

So when I do

```
print(-3^2)
= -9
```

and when I do

```
print((-3)^2)
= 9
```

I dont understand, wouldn’t the first one also be postive as a negative number times a negative number is positive? What difference does the brackets make?

Because, on the first one,

It’d only take the 3. Not the minus, to the power of 2.

While in the second one,

It’d take both to the power of 2.

nd remember :

(a) ^ n = a * a * a…(n times)

(-) ^ n = +

(n is an even number).

brackets - parenthesis,

is a ‘game changer’ tool,

It is really important to know when to put ones and when not.

A simple example -

`2 / (5*12 - 5)`

(2/55)

is not as same as -

`2/5*12-5`

( - 1/5)

1 Like

I have another question, how come when I do

```
(-5) ^ 1.2
```

it errors but when its a positive

```
(5) ^ 1.2
```

it doesn’t error?!??! how come the first one did!?!?!?

and then if the power is not a decimal then its fine:

```
(5) ^ 2
```

What do you mean by ‘error’?

1.2 is not an even number.

When the power is even, the minus would be gone [ turned into plus]

why does it have to be a even number?

When the power is even, the minus would be gone [ turned into plus]

I see, you get a `nan`

error. Hold on.

Okay, I printed these:

```
print(-5 ^ 1.2) -- works
print(5 ^ 1.2) -- works
print((-5) ^ 1.2) -- errors
```

When i say error i mean it returns nan (not a number).

so when i do

```
print((-5) ^ 1.2)
=nan
```

and then i do

```
print((5) ^ 1.2)
=6.89864830730607
```

how come the first one doesnt return a number?

I dont see any point having those parenthesis in this case.

Since the power is positive and not even, the partnethesis don’t matter.

```
print(-5 ^ 1.2) -- works
print(5 ^ 1.2) -- works
print((-5) ^2) -- works
print((-5) ^-2) -- works
```

The partenthesis only matter when you have either a long expression with multiple operations, or if the power is even and you want negative to become positive.

Also, have you tried to use `math.pow`

too?

but u know how if you do

```
print(-5 ^ 1.2)
```

the answer is negative, but what if you wanted to add the paranthesis so the answer is positive (hence a negative times a negative is positive), i tried this on the google calculator and i dont know why it doesn’t work

```
print((-5) ^ 1.2)
```

Because the parenthesis dont really do anything here, they dont affect it, and I think this is why the issue occurrs.

But as I’ve said before,

Since 1.2 is not even, raising both 5 and -5 to that power, would result in opposite results.

opposite results? I assume you mean a negative to positive and a positive to negative.

So when I do

```
-5 ^ 1.2
=-6.898648307306074
```

it doesnt print a positive, same when doing it to the power of positive 5.

When I print 5 ^ 1.2 , I do get a positive result.

And what I meant is:

5^1.2 = 6.898

-5^1.2 = -6.898

Because complex numbers is not in the domaim of Luau VM number data type so it’ll return NaN instead.

2 Likes

But it doesn’t require complex numbers? The odd roots of a negative number are real, so I assume this just a weird quirk of exponents using floating points.

*Edit: see below why I was wrong*

There is no quirk because it is not an odd root. `(-5)^1.2 = (-5)^(12/10)`

which as you can see involves the even root of a negative number, which requires complex numbers.

I put in the equation to desmos and it spit back a real answer, and if you try `(-5)^0.2`

in Roblox, which should be the 5th root of -5, it still spits out nan.

1 Like

can you please explain simply what this means, im having a hard time comprehending this.

I stand corrected then.

Either way the §9.2.1 of IEEE 754:2008 states that

pow (x, y) signals the invalid operation exception for finite x < 0 and finite non-integer y.

(in most cases, “signals the invalid operation excpetion” basically means that it returns NaN)

2 Likes