Operators
Overview
An operator is a symbol that causes an operation to be performed on the two values to either side of it. There are four types of operators: arithmetic, logical, string, and pattern matching. Pattern matching is described in the MATCH reference page.
Spaces are permitted (but not required) between operators and their operands.
The following types of operators are supported:
Arithmetic Operators
The following are the arithmetic operators supported by Caché MVBasic:
=  Numeric equality (assignment) operator. a=5+3 
+  Addition operator. a=5+3 
++  Increment operator. a++ 
+=  Increment (addition assignment) operator. a+=3 
–  Subtraction operator. a=53 
––  Decrement operator. a 
–=  Decrement (subtraction assignment) operator. a=3 
*  Multiplication operator. a=5*3 
*=  Multiplication assignment operator. a*=3 
/  Division operator. a=5/3 
/=  Division assignment operator. a/=3 
**  Exponentiation operator. a=5**3 
^  Exponentiation operator. a=5^3 
( )  Grouping (nesting) operator. a=((5+3)*2)+1 
The division operator (/) performs exact division, returning a fractional quotient. To perform integer division, truncating the fractional portion of the quotient, use the DIV function. To return the modulo of integer division, use the MOD function. You cannot divide a number by 0. Attempting to do so results in a <DIVIDE> error.
The exponentiation operators (** or ^) can perform exponentiation by raising any base number (num) to any power (exponent), subject to the following: If num is nonzero and exponent is 0, exponentiation returns 1. If num and exponent are both 0, exponentiation returns 0. If num is 0 and exponent is a nonzero negative number, exponentiation generates an <ILLEGAL VALUE> error. If num is a nonzero negative number and exponent is a fractional number, exponentiation generates an <ILLEGAL VALUE> error. Very large positive exponent values (such as 9**153) or very small num values with a negative exponent (such as .00005**30) may result in an overflow, generating a <MAXNUMBER> error. Very large negative exponent values (such as 9**135) or very small num values with a positive exponent (such as .00005**30) may result in an underflow, returning 0. You can also perform exponentiation using the PWR function.
By default, Caché MVBasic arithmetic operators do not perform vector arithmetic on the elements of dynamic arrays. To perform vector arithmetic, use the ADDS, SUBS, MULS, DIVS, MODS, and PWRS functions. In some MultiValue emulations the arithmetic operators (+, , *, /, **) do perform vector arithmetic on dynamic arrays, as described below.
By default, Caché MVBasic order of operations is to perform exponentiation, then division, then multiplication, then subtraction, then addition. You can change this order of operations by using parentheses to nest operations. Note that ObjectScript uses a different order of operations: it uses strict lefttoright evaluation of arithmetic operators.
Emulation
INFORMATION, jBASE, PIOpen, Prime, and UniData set $OPTIONS VEC.MATH. This causes the five basic arithmetic operators to perform vector arithmetic on dynamic arrays. Thus the + operator is equivalent to the ADDS function. The – operator is equivalent to the SUBS function. The * operator is equivalent to the MULS function. The / operator is equivalent to the DIVS function. The ** operator is equivalent to the PWRS function. These operators perform vector arithmetic when supplied dynamic array arguments, and perform simple arithmetic operations when supplied numeric arguments.
Logical Operators
Logical operators result in a boolean result, either 1 (True) or 0 (False). Caché MVBasic supports comparison logical operators (equal to, greater than) and logic operators that associate multiple comparison logical operators (AND, OR).
Comparison Logical Operators
Logical operators can compare numbers, strings, etc. String comparisons are casesensitive. Strings are compared characterbycharacter. A string is logically “greater than” when a character is higher in collation sequence than its corresponding character. For example, "fred">"Fred"=1 (True), because “f” is higher in the ASCII sequence than “F”. "fred">"fre"=1 (True), because “d” is higher in the ASCII sequence than null.
=
EQ 
Equal to operator. 
<
LT 
Less Than operator. 
>
GT 
Greater Than operator. 
<=
=<
#>
LE 
Less Than or Equal to operator. 
>=
=>
#<
GE 
Greater Than or Equal to operator. 
<>
#
NE 
Not equal to operator. 
The following example demonstrates the equality operator:
! Strings are casesensitive: PRINT "Fred"="Fred" ! Returns 1 (True) PRINT "Fred"="fred" ! Returns 0 (false) ! Number/Numeric strings equality: PRINT "7"=7 ! Returns 1 (True) PRINT +007.00="7" ! Returns 1 (True) PRINT "+007.00"="7" ! Returns 1 (True) ! Null string equality: PRINT ""="" ! Returns 1 (True) PRINT ""=NULL ! Returns 1 (True) PRINT ""=0 ! Returns 0 (False) ! Unassigned variables equality ! (variables aaa and bbb are unassigned): PRINT aaa=bbb ! Returns 1 (True) PRINT aaa="" ! Returns 1 (True) PRINT aaa=NULL ! Returns 1 (True)
AND / OR Logical Operators
The following logical operators are used to specify multiple equality operations:
&
AND 
Logical AND operator. 
!
OR 
Logical OR operator. 
Left and Right Side Evaluation
MultiValue emulations differ in how to handle evaluation of AND and OR logical operations. Some MultiValue systems support full logical evaluation: both sides of the logical operator are evaluated, regardless of the logical value of the left side operation. Other MultiValue systems support partial logical evaluation (short circuit evaluation):

AND operation: evaluate the left side operation, and if it evaluates to False, do not evaluate the right side operation.

OR operation: evaluate the left side operation, and if it evaluates to True, do not evaluate the right side operation.
Caché MultiValue uses partial logical evaluation by default. The following emulations also default to partial logical evaluation: IN2, INFORMATION, jBASE, PICK, PIOpen, Prime, UDPICK, Ultimate, UniData, and UniVerse. The following emulations default to full logical evaluation: D3, MVBase, R83, Power95, and Reality.
You can use $OPTIONS FULL.LOGICAL.EVALUATION to enable full logical evaluation. You can use $OPTIONS FULL.LOGICAL.EVALUATION to enable partial logical evaluation.
Order of Evaluation
Caché MultiValue gives equal precedence to the AND and the OR logical operators. This means that multiple AND and OR logical operations are evaluated in strict lefttoright sequence, unless parentheses are provided to specify evaluation sequence. Caché uses the same strict lefttoright order of evaluation.
String Operators
The following are the string operators supported by Caché MVBasic:
:
CAT 
Concatenation operator. Placed between two expressions, strings, or numeric values to be concatenated. When using the : operator you can include or omit blank spaces. When using the CAT operator you must use a blank space when concatenating a variable. 
:=  Concatenation assignment operator. Placed between a variable name and a value to be concatenated to the variable's value. For example, if a="abcd" using a:="efg" results in a="abcdefg". 
[] 
Substring extract operator. Placed after a string, the brackets enclose positive integers:
string[start,length] specifies the start position and length of the substring to be extracted from the start of the string.
string[length] specifies the length of the substring to be extracted from the end of the string.
Emulation: IN2: the default setting IN2.SUBSTR makes string[n] equivalent to string[n,1], specifying the start position (n) from the beginning of the string and a length of 1. Reality: the default setting REAL.SUBSTR causes string[start,end] to count start from the beginning of the string and to count –end as the ending point, counting from the end of the string; string[start,n] counts both the starting and ending points from the end of the string. 
<>  Dynamic array element extract or replacement operator. For further details see the Dynamic Arrays page of this manual. 
The following example demonstrates the string concatenation operator:
! String concatenation: PRINT "fire":"fly" ! Returns "firefly" PRINT "fire":"":"fly" ! Returns "firefly" PRINT "fire":" ":"fly" ! Returns "fire fly" ! Number/Numeric strings concatenation: PRINT "7":7 ! Returns "77" PRINT +007.00:"7" ! Returns "77" PRINT 7:"+007.00" ! Returns "7+007.00" PRINT .0:.0 ! Returns "00" ! Null string concatenation: PRINT "":"" ! Returns null string PRINT "":NULL ! Returns null string ! Unassigned variables concatenation ! (variables aaa and bbb are unassigned): PRINT aaa:bbb ! Returns null string
The following example demonstrates the substring extract operator:
x="The quick brown fox" ! Extract from beginning of string: PRINT x[5,5] ! Returns "quick" PRINT x[5,99] ! Returns "quick brown fox" PRINT x[1,3] ! Returns "The" PRINT x[0,3] ! Returns "The" PRINT x["",3] ! Returns "The" ! Extract from end of string: PRINT x[3] ! Returns "fox" PRINT x[1] ! Returns "x" PRINT x[0] ! Returns null string PRINT x[""] ! Returns null string