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?

1 Answer 1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.