General EQWatcher Concepts > Venturing into the Unknown  > Mathematics


List of commands -- note that "integer" is not a valid user data type, it means any of char, byte, signed or unsigned long

abs(integer expression)

angle(integer expression)

sqrt(integer expression)


abs(integer expression) Command

Gives the absolute value (turns negative into positive, positive remains positive)

Return value

the absolute value of its parameter

Parameters

expression

Any valid expression that evaluates to an integer

Example

// This example finds the absolute value of -4, which is 4, and speaks it synchronously

function main()
{
  unsigned long test;
  test=abs(-4);
  SpeakSync(test);  // note: SpeakSync(abs(-4)); will currently give a syntax error, do it like this.
}
 


angle(integer expression) Command

Gives the angle in degrees, 0 to 89, based on expression being the Tangent*100 of this angle. 

The calculation is done by using a min point and max point (0 and 90), and comparing the desired result to the tangent midpoint of the min and max.  Basically this means that if expression is equal to Tan(45)*100 the angle is computed in a single cycle of the loop.  If the expression is equal to Tan(60)*100, the angle is computed by checking 45, then (max-min/2)+min... then since 60>mid, min is set to mid (if 60<mid, max is set to mid), and repeats.  This is fairly fast and efficient for this purpose, but is to be considered SLOW compared to all other built in commands, since it is the only command requiring looping.  It's much better than looping the full 90 times though, and the other alternative would be to use a table of all possible values, which is not worth it for our purpose.

Return value

the square root of its parameter

Parameters

expression

Any valid expression that evaluates to an integer

Example

// This example finds the square root of 4, which is 2, and speaks it synchronously

function main()
{
  unsigned long test;
  test=sqrt(4);
  SpeakSync(test);  // note: SpeakSync(sqrt(4)); will currently give a syntax error, do it like this.
}
 


sqrt(integer expression) Command

Gives the square root

Return value

the square root of its parameter

Parameters

expression

Any valid expression that evaluates to an integer

Example

// This example finds the square root of 4, which is 2, and speaks it synchronously

function main()
{
  unsigned long test;
  test=sqrt(4);
  SpeakSync(test);  // note: SpeakSync(sqrt(4)); will currently give a syntax error, do it like this.
}