Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Priority 5
Priority 5 operators

It describes the following operators with priority 5.


+x + yAddition operator
-x - ySubtraction operator

They are binary arithmetic operators and perform arithmetic operations to the left and right operands.

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


Table of contents:


Addition operator

Subtraction operator

Addition operator

Addition operator is an operator for adding the operands.

The class of the result depends on the class of the operand.

If there is the real class in the operand, the class of the result is real.


real r0 = 123.5 + 10.0; // The left is real and the right is real. Therefore, result is real.

real r1 = 123.5 + 10; // The left is real and the right is int. Therefore, result is real.

real r2 = 123.5 + 10L; // The left is real and right is long. Therefore, result is real.


If there is no real class in the operand and there is the long class, the class of the result is long.


long l0 = 123L + 10L; // The left is long and the right is long. Therefore, result is long.

long l1 = 123L + 10; // The left is long and the right is int. Therefore, result is long.


Otherwise the class of the result is int.


real i0 = 123 + 10; // The left is int and the right is int. Therefore, 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 the left and right operands are string, The + symbol is a concatenation operator, not an addition operator.

The concatenation operator returns an new instance of the string class 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

Subtraction operator is an operator for subtracting the operands.

The class of the result depends on the class of the operand.

If there is the real class in the operand, the class of the result is real.


real r0 = 123.5 - 10.0; // The left is real and the right is real. Therefore, result is real.

real r1 = 123.5 - 10; // The left is real and the right is int. Therefore, result is real.

real r2 = 123.5 - 10L; // The left is real and right is long. Therefore, result is real.


If there is no real class in the operand and there is the long class, the class of the result is long.


long l0 = 123L - 10L; // The left is long and the right is long. Therefore, result is long.

long l1 = 123L - 10; // The left is long and the right is int. Therefore, result is long.


Otherwise the class of the result is int.


real i0 = 123 - 10; // The left is int and the right is int. Therefore, 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.

Next
Previous
Copyright © Rice All rights reserved.