> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/functions/internal-functions/math-functions.md).

# 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:

Code-Snippet

```
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;

Code-Snippet

```
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:

Code-Snippet

```
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

***

### pow

Code-Snippet

```
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:

Code-Snippet

```
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

Code-Snippet

```
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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/functions/internal-functions/math-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
