Siebel eScript Language Reference > Siebel eScript Language Overview > Operators >

Mathematical Operators


Mathematical operators are used to make calculations using mathematical data. The following sections illustrate the mathematical operators in Siebel eScript.

Basic Arithmetic

The arithmetic operators in Siebel eScript are standard.

=

assignment

assigns a value to a variable

+

addition

adds two numbers

-

subtraction

subtracts a number from another

*

multiplication

multiplies two numbers

/

division

divides a number by another

%

modulo

returns a remainder after division

The following examples use variables and arithmetic operators:

var i;
i = 2;     //i is now 2
i = i + 3; //i is now 5, (2 + 3)
i = i - 3; //i is now 2, (5 - 3)
i = i * 5; //i is now 10, (2 * 5)
i = i / 3; //i is now 3, (10 / 3) (the remainder is ignored)
i = 10;    //i is now 10
i = i % 3;  //i is now 1, (10 mod 3)

Expressions may be grouped to affect the sequence of processing. Multiplications and divisions are calculated for an expression before additions and subtractions unless parentheses are used to override the normal order. Expressions inside parentheses are processed before other calculations.

In the following examples, the information in the remarks represents intermediate forms of the example calculations.

Notice that, because of the order of precedence,

4 * 7 - 5 * 3; //28 - 15 = 13

has the same meaning as

(4 * 7) - (5 * 3); //28 - 15 = 13/

but has a different meaning from

4 * (7 - 5) * 3; //4 * 2 * 3 = 24

which is also different from

4 * (7 - (5 * 3)); //4 * -8 = -32

The use of parentheses is recommended whenever there may be confusion about how the expression is to be evaluated, even when parentheses are not required.

Assignment Arithmetic

Each of the operators shown in the previous section can be combined with the assignment operator, =, as a shortcut for performing operations. Such assignments use the value to the right of the assignment operator to perform an operation on the value to the left. The result of the operation is then assigned to the value on the left.

=

assignment

assigns a value to a variable

+=

assign addition

adds a value to a variable

-=

assign subtraction

subtracts a value from a variable

*=

assign multiplication

multiplies a variable by a value

/=

assign division

divides a variable by a value

%=

assign remainder

returns a remainder after division

The following lines are examples using assignment arithmetic:

var i;
i = 2;  //i is now 2
i += 3; //i is now 5 (2 + 3),   same as i = i + 3
i -= 3; //i is now 2 (5 - 3),   same as i = i _ 3
i *= 5; //i is now 10 (2 * 5),  same as i = i * 5
i /= 3; //i is now 3 (10 / 3),  same as i = i / 3
i = 10; //i is now 10
i %= 3;  //i is now 1, (10 mod 3), same as i = i % 3

Auto-Increment (++) and Auto-Decrement (--)

To add 1 to a variable, use the auto-increment operator, ++. To subtract 1, use the auto-decrement, operator, --. These operators add or subtract 1 from the value to which they are applied. Thus, i++ is shorthand for i += 1, which is shorthand for i = i + 1.

The auto-increment and auto-decrement operators can be used before their variables, as a prefix operator, or after, as a suffix operator. If they are used before a variable, the variable is altered before it is used in a statement, and if used after, the variable is altered after it is used in the statement.

The following lines demonstrate prefix and postfix operations:

i = 4;

//i is 4

j = ++i;

//j is 5, i is 5

(i was incremented before use)

j = i++;

//j is 5, i is 6

(i was incremented after use)

j = --i;

//j is 5, i is 5

(i was decremented before use)

j = i--;

//j is 5, i is 4

(i was decremented after use)

i++;

//i is 5

(i was incremented)


 Siebel eScript Language Reference 
 Published: 18 April 2003