Mathematical Operators in Siebel eScript

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. They are described in Table 7.

Table 7. Basic Arithmetic Operators in Siebel eScript
Operator
Purpose
Description

=

Assignment

Assigns a value to a variable

+

-

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.333..., (10 / 3)
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. Table 8 lists these operators, their purposes, and descriptions.

Table 8. Basic Arithmetic Operators in Siebel eScript
Operator
Purpose
Description

=

Assignment

Assigns a value to a variable

+=

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.333...(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 they are used after, the variable is altered after it is used in the statement.

The lines in Table 9 demonstrate prefix and postfix operations.

Table 9. Auto-Increment and Auto-Decrement Operators in Siebel eScript
Example
Results
Description

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)