2

I'm currently executing the following (very simple) code in Julia:

-1^2

But for some reason the result is always:

-1

Now, if I put in parenthesis, then the answer is correct. So I'm curious as to why this is happening. I'm running this on a Jupyter Notebook.

marcogemaque
  • 461
  • 6
  • 14

1 Answers1

4

This is due to order of operations. Exponentiation takes precedence over Subtraction, so you get -(1^n) which is always -1.

Ashwin Rohit
  • 78
  • 1
  • 6