Without worrying about AppleScript's problems previously discussed,
why does the C function work at all?
Because unary minus has higher precedence than exclusive-or.
First, for those who don't already know, in C, "^" is the exclusive-or
operator, not the "power" operator.
"2^2" on its own produces zero. However, the above calculation is "(-2)
xor 2". Here's a C program that demonstrates. Put this code in a file
named "xortest.c":
The last line shows that it is only a deceptive coincidence that "-2^2
= -4" looks like "-(2 to the power of 2)". If you change either of the
two numbers the result no longer looks confusingly like "^" is the
"power" operator.