Operators

<< Click to Display Table of Contents >>

Manual > Script Guide > Script Ver2 (SC2 syntax) >

Operators

Operators

The following operators can be used in a script:

 

Operator

Arithmetic Operators

 

Minus sign

-

Used to specify the negated value of an expression.

Multiplication

*

Calculates the product of two numbers.

division

/

Calculates the quotient of two numbers.

Add

+

Calculates the sum of two numbers.

Subtract

-

Finds the difference between two numbers.

 

Comparison Operators

 

equal

==

Compares two numbers and returns TRUE if they are equal.

Not equal

!=

Compares two numbers and returns TRUE if they are not equal.

Less than

<

Compares two numbers and returns TRUE if the left value is less than the right value.

Greater than

>

Compares two numbers and returns TRUE if the left value is greater than the right value.

below

<=

Compares two numbers and returns TRUE if the left value is less than or equal to the right value.

End

>=

Compares two numbers and returns TRUE if the left value is greater than or equal to the right value.

 

Logical Operators

 

Logical negation

!

Returns the logical negation of an expression.

Logical AND

&&

Performs a logical AND on two expressions.

Logical OR

||

Performs a logical disjunction on two expressions.

 

Bitwise Operators

 

And operator

&

Bitwise And operator (compares bits as integers). If the left expression is a string, it is concatenated as a string.

Or Operator

|

Bitwise Or operator (bitwise comparison as integers).

 

 

Operator features and usage examples

Implicit string composition and arithmetic operations

 

If the contents of both operands are strings, the addition is treated as string composition. However, if one operand is a number and the other is a string, the addition is performed as an operation between numbers if the contents of the string are numbers.

 

var a = "Hello" + " " + "World";//The string "Hello World" is assigned to the variable a
var b = "1" + 2; //The number 3 is assigned to the variable b
var d = 1 + "2"; //Similarly, it becomes the number 3

 

 


 

Boolean interpretation for arithmetic operations

 

When you perform arithmetic on Boolean values, T is converted to 1 and F is converted to 0.

 

var a = T + T + T + F + T; // results in the value 4 (1+1+1+0+1) 
var b = T * 123 + F * 456; // results in the value 123 (1*123 + 0*456)

 

 


 

Adding and Subtracting Times

 

For time, you can add or subtract the following combinations of values:

 

1)[Time] + [Number] or [Time] - [Number]
The number is interpreted as seconds, which can be used to advance or reverse the time value.
 

var a = #2004/1/1 0:0:0#;
var b = a + 10; // b is added 10 seconds to a, resulting in #2004/1/1 0:0:10#
var d = a + 10.123; // b is added 10 seconds, or 123 ms, to a, resulting in #2004/1/1 0:0:10.123#

 
 

2)[Time] - [Time]
Returns the time difference as a number in seconds.
 

var a = #2004/1/1 0:0:0#;
var b = #2004/1/1 0:1:0#;
var d = b - a; // d is 60 (1 minute difference = 60 seconds)

 

 


 

Operations on Arrays

 

■ Arithmetic operators (+, -, *, /)

 

a = c(1,2,3);
b = a + 1; // b becomes c(2, 3, 4)
d = a - 1; // d becomes c(0, 1, 2)
e = a * 2; // e becomes c(2, 4, 6)
f = a / 2; // f becomes c(0.5, 1, 1.5)
g = a + c(2, 3, 4); // g becomes c(3, 5, 7)

 

 

■ Comparison operators (<, <=, >, >=, ==)

 

a = c(1,2,3);
b = a < 2; // b becomes c(T, F, F)
d = a <= 2; // d becomes c(T, T, F)
e = a > 2; // e becomes c(F, F, T)
f = a >= 2; // f becomes c(F, T, T)
g = a == 2; // f becomes c(F, T, F)
h = a > c(3, 2, 1); // g becomes c(F, F, T)

 

 


 

Adding and Subtracting Times

 

In the case of multidimensional arrays, the operation is performed on all elements at once.

 

a = c(c(1,2,3), c(4,5,6));
b = a + 2; // b becomes c(c(3,4,5), c(6,7,8))

 

hint

When performing an operation on arrays with different numbers of elements, such as "c(1,2,3,4,5,6,7,8) + c(1,2,3)", the right-hand side c(1,2,3) is used for the repeated operation. In other words, "c(1,2,3,4,5,6,7,8) + c(1,2,3)" becomes "c(1,2,3,4,5,6,7,8) + c(1,2,3,1,2,3,1,2)".

gives the same result, i.e. c(2,4,6,5,7,9,8,10).

 

 


Numeric bit operations

 

To get the i-th bit in a binary number or to turn only the i-th bit ON/OFF, use the bit operators ('&' and '|').

 

example)

var b = (a & 0x1) > 0; // If the 1st bit of a's number is 1, then b will be T. 
var b = (a & 0x2) > 0; // If the 2nd bit of a's number is 1, then b will be T. 
var b = (a & 0x4) > 0; // If the 3rd bit of a's number is 1, then b will be T. 
var b = (a & 0x8) > 0; // If the 4th bit of a's number is 1, then b will be T. 

var a = a | 0x1; // Set the 1st bit of a's number to 1. 
var a = a | 0x2; // Set the 2nd bit of a's number to 1. 
var a = a | 0x4; // Set the 3rd bit of a's number to 1. 
var a = a | 0x8; // Sets the fourth bit of the numeric value of a to 1. 

var a = a & 0xFFFE; // Sets the first bit of the word value of a to 0. 
var a = a & 0xFFFD; // Sets the second bit of the word value of a to 0. 
var a = a & 0xFFFB; // Sets the third bit of the word value of a to 0. 
var a = a & 0xFFF7; // Sets the fourth bit of the word value of a to 0.