Priority 5 operators

+x + yAddition operator
-x - ySubtraction operator

They are binary arithmetic operators and have left-associativity.

The operand must be one of the int, long, or real. These can be mixed in operands.


Table of contents:


Addition operator

Subtraction operator

Addition operator

This is an operator for adding operands.

The result class will be the one with the widest range of operands: real > long > int.


real r0 = 123.5 + 10.0; // Left is real, right is real, result is real.

real r1 = 123.5 + 10; // Left is real, right is int, result is real.

real r2 = 123.5 + 10L; // Left is real, right is long, result is real.

long l0 = 123L + 10L; // Left is long, right is long, result is long.

long l1 = 123L + 10; // Left is long, right is int, result is long.

int i0 = 123 + 10; // Left is int, right is int, result is int.


If the value of the result exceeds the range of the class, an exception is thrown.

If operands return the proxy class, the entity of the proxy is automatically used. The result is the same as calling the Entity getter of the proxy class.


int i = 10;

real r = 10.5;

proxy pro = new proxy(i);

proxy pro2 = new proxy(r);

real r2 = pro2 + pro; // r2 is 20.5.

Concatenation operator

If operands are string, the operator is a concatenation operator.

The concatenation operator returns a new string that concatenated the operands.


string s = "Hellow " + "world!"; // The result is "Hellow world!".

If operands return the proxy class, the entity of the proxy is automatically used. The result is the same as calling the Entity getter of the proxy class.


string s = "A";

string s2 = "a";

proxy pro = new proxy(s);

proxy pro2 = new proxy(s2);

string s3 = pro2 + pro; // s3 is "aA".

Subtraction operator

This is an operator for subtracting operands.

The result class will be the one with the widest range of operands: real > long > int.


real r0 = 123.5 - 10.0; // Left is real, right is real, result is real.

real r1 = 123.5 - 10; // Left is real, right is int, result is real.

real r2 = 123.5 - 10L; // Left is real, right is long, result is real.

long l0 = 123L - 10L; // Left is long, right is long, result is long.

long l1 = 123L - 10; // Left is long, right is int, result is long.

int i0 = 123 - 10; // Left is int, right is int, result is int.


If the value of the result exceeds the range of the class, an exception is thrown.

If operands return the proxy class, the entity of the proxy is automatically used. The result is the same as calling the Entity getter of the proxy class.


int i = 10;

real r = 10.5;

proxy pro = new proxy(i);

proxy pro2 = new proxy(r);

real r2 = pro2 - pro; // r2 is 0.5.

Copyright © Rice All rights reserved.