|
Strange Behavior of power operator (^) in Cscript john geddes from Australia [6 posts] |
12 year
|
Hi again!
I've noticed strange behavior with the power operator "^".
From my intuition:
2^2 = 4, 2^3=8
-1^2 = 1 etc...
What i noticed is that in cscript, it does not behave like that at all. I cannot figure out what the "^" is doing.
I get things like:
2^2 = 0, -2^2 = -4, -3^2 = -1, 2^3 = 1 etc... just odd...
For reference, this is how I'm checking them:
int test = 2^3;
printf("%d",test);
Also, i can't seem to find if the Cscript has an 'absolute' function such as "a = |a|"
(coming from Matlab where it's "a = abs(a)")
Which brings me to my next point, I can't seem to find a complete list of math functions available to use in the scripts. Am I not looking in the right place?
Thanks!
|
|
|
Anonymous |
12 year
|
Botagar,
In C the "^" is not a power operator but an exclusive OR ... otherwise know as XOR.
The power operator is typically a function like the abs.
printf("%f\r\n", pow(2,2));
printf("%f\r\n", fabs(-2));
The CScript module uses PicoC from
http://code.google.com/p/picoc/
which you can find some more information about. Its not much so if you run into issues let us know.
STeven.
|
|
|
Anonymous |
12 year
|
|
|
john geddes from Australia [6 posts] |
12 year
|
Ahh thanks a tonne again!
I got too used to matlab and forgot that ^ also meant XOR.
also cheers for the list!
|
|