To properly display this page you need a browser with JavaScript support.
 User's Manual GPC Language Reference Math Functions

# Math Functions

The GPC's math functions will only handle values within the range of the 16 bits signed integers.

Related GPC Functions:

abs      Returns the absolute value of a expression
inv      Returns the inverted (signal) value of a expression
pow      Raises a number to the given power
isqrt    Calculate an integer square root
irand    Generate an pseudo random integer

1. abs

Returns the absolute value of a expression.

Prototype:

int abs ( <expression> )

Parameters:

<expression>  : anything that has a value

Return:

the absolute value

Example:

 a = abs(5);  /* a = 5 */ b = abs(-5); /* b = 5 */

2. inv

Returns the inverted (signal) value of a expression.

Prototype:

int inv ( <expression> )

Parameters:

<expression>  : anything that has a value

Return:

the inverted (signal) value

Example:

 a = inv(5);  /* a = -5 */ b = inv(-5); /* b = 5  */

3. pow

This function shall compute the value of X raised to the power Y. CAUTION: risk of integer overflow, it may occur when the pow operation attempts to create a numeric value that is larger then a 16 bit signed integer.

Prototype:

int pow ( <expressionX>, <expressionY> )

Parameters:

<expressionX> : anything that has a value
<expressionY> : anything that has a value

Return:

upon successful completion, pow shall return the value of X raised to the power Y

Example:

 a = pow(2, 3);  /* a = 8 */

4. isqrt

Calculates an integer square root. The integer square root of a positive integer n is the positive integer m which is the greatest integer less than or equal to the square root of n.

Prototype:

int isqrt ( <expression> )

Parameters:

<expression>  : anything that has a value

Return:

upon successful completion, isqrt shall return the integer square root of given expression

Example:

 x = isqrt(17);  /* x = 4 */

5. irand

Generate an pseudo random integer within min, max arguments. For example, if you want a random number between -5 and 15 (inclusive), use rand(-5, 15).

Prototype:

int irand ( <min>, <max> )

Parameters:

<min>  : The lowest value to return
<max>  : The highest value to return

Return:

a pseudo random integer between min and max (inclusive).

Example:

 x = irand(-174, 84);  /* x = -57 */