0

Might be a stupid question. I have checked this many times, it seems as if only the following statement works:

value = (n**2+n)/2;

And not:

value = (n^2+n)/2;

Since it gives unexpected, strangely low and volatile results.

Although there are sources on the net which show usage with ^ like this. I finally found out that only ** is right. Is it possible that the ^ still works in some situations or is this just an error of some documentations?

questionto42
  • 111
  • 5

1 Answers1

1

Looking at the latest Solidity docs there are both operation for integers available:

** - exponentiation

^ - bitwise exclusive or

So in your case only ** makes sense.

I am not aware of any version where this was different.

Richard
  • 4,934
  • 2
  • 7
  • 25