Caché MultiValue Basic Reference
Operators


Arithmetic, logical, and string 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:
The following are the arithmetic operators supported by Caché MVBasic:
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 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.
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:
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.
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.
The following are the string operators supported by Caché MVBasic:
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
See Also
Copyright © 19972019 InterSystems Corporation, Cambridge, MA