GPC Developer Guides
...
Functions
Internal Functions
Math Functions
in this section are the gpc functions used to perform specific mathematical operations two important things to note when working while performing math computations in gpc is that it is a signed 16bit environment so all operations must work within that range which is 32768 to +32767 and gpc only supports integer values which means any fractions will be rounded down to a whole value function description abs returns an absolute value of a number inv returns the inverse value of a number pow raise and value to the specified power isqrt calculates an integer square root random generates a random value between the specified range clamp the clamp() function clamps a value between an upper and lower bound clamp() enables selecting a middle value within a range of values between a defined minimum and maximum it takes three parameters a minimum value, a preferred value, and a maximum allowed value min gets the minimum of two values max gets the maximum of two values abs abs command returns the absolute value of an expression an absolute value is a number without regard for its sign, for example, the absolute value of 8 and 8 is 8 an absolute value can also be thought of as its distance from zero which is always a positive value one of the popular uses for the abs command is when working with axis to start combos such as in fighting games where many users tend to use the right stick to start a combo so if you wished for the same combo to be run if the right stick was pushed left or right, instead of using the 'or' ( || ) operator or using two if commands you could just do this gpc main { if( abs(get val(xb1 rx)) > 70 ) // if rx is greater than 70 or 70 combo run(my combo); } combo my combo { //do something } 🔴 syntax abs ( \<expression> ); ⚪ parameters \<expression> any expression which has a value 🔵 returns the absolute value of the expression inv inv returns the inverted value of an expression or number this means a positive value will be turned into a negative value and vice versa, which is the same as multiplying the value by 1 for example; gpc int a = 100; int b = 50; main { a = inv(a); // a = 100 b = inv(b); // b = 50 } one of the popular uses for this command is to invert the right sticks y axis for example, if you prefer to play with an inverted aim but come across a game that doesn't support it, with one line of code you can have the cronus invert the axis for you like so gpc main { // set ry to the inverse of its current value set val(xb1 ry, inv(get val(xb1 ry)) ); } 🔴 syntax inv( \<expression> ); ⚪ parameters \<expression> any expression which has a value 🔵 returns the inverted value of the expression gpc int a; main { a = pow(5, 3); // a = 125 (5³) or (5 5 5) } info this function must be used with caution as there is a risk of an integer overflow when using it this would occur when the function attempts to return a value greater than 32767 which is the maximum value for a signed 16 bit integer 🔴 syntax pow ( \<base value> , \<power value> ); ⚪ parameters \<base value> base number \<power value> power raised to the base value 🔵 returns it returns the base value raised to the power of the exponent isqrt isqrt returns the square root of a given value the square root of a value is the value that when multiplied by itself equals the given value for example, the square root of 25 is 5 (5 5 = 25) the return value is an integer which means any fractions will be dropped as shown below gpc int a; main { a = isqrt(10); // a = 3 the square root of 10 is 3 16 // gpc supports integer values only so the fraction is dropped } 🔴 syntax isqrt ( \<expression> ); ⚪ parameters \<expression> any expression which has a value 🔵 returns the square root of the given expression random random generates a random int between two numbers (minimum 32768 and maximum 32767) info this function is only available with cronus zen gpc int a = 5; // minimum value of the integer to randomize int b = 3999; // maximum value of the integer to randomize int c; main { c = random(a,b); // generates a random number and assigns the result to c; } 🔴 syntax random ( \<min value> , \<max value> ); ⚪ parameters \<min value> the minimum integer value to start your random number (minimum value 32768) \<max value> the maximum integer value to start your random number (maximum value 32767) 🔵 returns generates a random int value between the \<min value> and the \<max value> parameters