loading
 
Strange Behavior of power operator (^) in Cscript
john geddes from Australia  [6 posts]
11 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 11 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 11 year
We also added a list at the bottom of

http://www.roborealm.com/help/CScript_Program.php

as to which C functions are present in PicoC.

STeven.
john geddes from Australia  [6 posts] 11 year
Ahh thanks a tonne again!
I got too used to matlab and forgot that ^ also meant XOR.

also cheers for the list!

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index