> 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/operator-types.md).

# Operator Types

An operator is a symbol that tells the interpreter to perform specific mathematical, relational, or logical operations and produce the final result. This section details the operators available in GPC.

```gpc
int a = 10;
int b = 5;
int c = 0;

main {
    // assignment operators
    c = 5;       // c is set to a value of 5
    c += 5;      // c is set to a value of 10 (5 + 5 = 10)
    c -= 5;      // c is set to a value of 5 (10 - 5 = 5)
    c *= 5;      // c is set to a value of 25 (5 * 5 = 25)
    c /= 5;      // c is set to a value of 5 (25 / 5 = 5)
    c %= 5;      // c is set to a value of 0 (5 % 5 = 0)

    // mathematical operators
    c = a + b;   // addition, c = 15
    c = a - b;   // subtraction, c = 5
    c = a * b;   // multiplication, c = 50
    c = a / b;   // division, c = 2
    c++;         // increment, c = 3
    c--;         // decrement, c = 2

    // logical operators
    if(c != a)   // NOT: if c is not equal to a
    if(a && c)   // AND: if a and c are true
    if(a || c)   // OR: if a or c are true
    if(a ^^ c)   // XOR: if either a or c are true but not both

    // relational operators
    if(c == 10)  // equal to: if c is equal to 10
    if(c != 50)  // not equal to: if c is not equal to 50
    if(c < 20)   // less than: if c is less than 20
    if(c > 30)   // greater than: if c is greater than 30
    if(c <= 40)  // less than or equal to: if c is less than or equal to 40
    if(c >= 40)  // greater than or equal to: if c is greater than or equal to 40
}
```

***

### Assignment

`=` is the assignment operator. Think of this as "gets set to" rather than "equal to". When `=` is used, the left operand gets set to the value of the right operand.

There are also a number of shorthands for common tasks such as incrementing a value by a set amount:

| Operator | Description                                                                              |
| -------- | ---------------------------------------------------------------------------------------- |
| `=`      | Sets the left operand to the value of the right operand                                  |
| `+=`     | Sets the left operand to the value of the left operand plus the right operand            |
| `-=`     | Sets the left operand to the value of the left operand minus the right operand           |
| `*=`     | Sets the left operand to the value of the left operand multiplied by the right operand   |
| `/=`     | Sets the left operand to the value of the left operand divided by the right operand      |
| `%=`     | Sets the left operand to the remainder of dividing the left operand by the right operand |

In the example below, assume `a` holds a value of 10:

```gpc
a = 5;       // a is set to 5
a += 5;      // a is set to 10
a -= 5;      // a is set to 5
a *= 5;      // a is set to 25
a /= 5;      // a is set to 5
a %= 3;      // a is set to 2
```

***

### Arithmetic

It is often necessary to perform arithmetic on two values. The following table lists the arithmetic operators available in GPC:

| Operator | Description                                         |
| -------- | --------------------------------------------------- |
| `+`      | Adds two operands                                   |
| `-`      | Subtracts right operand from the left operand       |
| `*`      | Multiplies both operands                            |
| `/`      | Divides the left operand by the right operand       |
| `%`      | Modulus, gives the remainder of an integer division |
| `++`     | Increments by 1                                     |
| `--`     | Decrements by 1                                     |

In the example below, assume `a` holds a value of 10 and `b` holds a value of 5:

```gpc
a + b;       // will give a value of 15
a - b;       // will give a value of 5
a * b;       // will give a value of 50
a / b;       // will give a value of 2
a % b;       // will give a value of 0
a++;         // will give a value of 11
a--;         // will give a value of 9
```

{% hint style="info" %} GPC does not support fractions so the division operator `/` will drop any fractions. For example, 10 / 3 = 3 as the fraction is dropped. It also does not round, so 3 / 4 = 0 and not 1. {% endhint %}

***

### Logical

Logical operators are important in any programming language as they allow to tell the interpreter to make decisions based on certain conditions. The following table lists the logical operators within the GPC language:

| Operator | Description                                                                          |
| -------- | ------------------------------------------------------------------------------------ |
| `&&`     | AND operator, if both operands are true then the condition becomes true              |
| `\|\|`   | OR operator, if either operand is true then the condition becomes true               |
| `^^`     | XOR operator, if either operand is true but not both then the condition becomes true |
| `!`      | NOT operator, reverses the logical state of an operand                               |

In the example below, assume `a` holds a value of 1 and `b` holds a value of 0:

```gpc
a && b       // value is false
a || b       // value is true
a ^^ b       // value is true
!b           // value is true
!a           // value is false
```

***

### Relational

Relational operators produce boolean results (true or false) while comparing two operands. The following table lists the relational operators which are available in GPC:

| Operator | Description                                                                                                                             |
| -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `==`     | Equal to, if the left operand holds the same value as the right then the condition becomes true                                         |
| `!=`     | Not equal to, if the left operand does not hold the same value as the right then the condition becomes true                             |
| `>`      | Greater than, if the left operand holds a value greater than the right then the condition becomes true                                  |
| `<`      | Less than, if the left operand holds a value less than the right then the condition becomes true                                        |
| `>=`     | Greater than or equal to, if the left operand holds a value which is greater than or equal to the right then the condition becomes true |
| `<=`     | Less than or equal to, if the left operand holds a value which is less than or equal to the right then the condition becomes true       |

In the example below, assume `a` holds a value of 30 and `b` holds a value of 10:

```gpc
a == b       // is false
a != b       // is true
a > b        // is true
a < b        // is false
a >= b       // is true
a <= b       // is false
```

***

### Binary

Binary is the same as logical, except they work with bits.

| Operator | Description                                                               |
| -------- | ------------------------------------------------------------------------- |
| `&`      | AND operator, if both bits are 1 then the resulting bit is 1              |
| `\|`     | OR operator, if either bit is 1 then the resulting bit is 1               |
| `^`      | XOR operator, if either bit is 1 but not both then the resulting bit is 1 |
| `<<`     | Left shift operator, shifts bits to the left by the specified amount      |
| `>>`     | Right shift operator, shifts bits to the right by the specified amount    |
| `~`      | NOT operator, inverts all bits                                            |

In the example below:

```gpc
3 & 1        // = 1
1 | 2        // = 3
1 ^ 2        // = 3
1 << 1       // = 2
1 >> 1       // = 0
~1           // = -2
```


---

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

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/operator-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
