GPC Developer Guides
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 operator 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) // mathmatical 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 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 short hands 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 15 a = 5; // a is set to 5 a = 5; // a is set to 50 a /= 5; // a is set to 2 a %= 3; // a is set to 1 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 note, 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 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 operators 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 tables list the relational operands 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 left then the condition becomes true < less than, if the left operand holds a value less than the left 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 operators 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 << left shift operator, less than, if the left operand holds a value less than the left then the condition becomes true >> right shift operator, greater than, if the left operand holds a value greater than the left then the condition becomes true not operator, subtracts right operand from the left operand in the example below, gpc 3 & 1 = 1 1 | 2 = 3 1 ^ 2 = 1 << 1 = 2 1 >> 1 = 0 1 = 32768