[Contents] [Prev] [Next] [Index] [Report an Error]

Operators

You can use operators to perform specific actions on local variables or literals, resulting in some string or numeric value. Table 59 lists the available macro operators in order of precedence by operation type. Operators within a given row are equal in precedence.

Table 59: Macro Operators

Operation Type

Operators

 

Extraction

substr()

rand()

round()

truncate()

 

 

 

String

$

 

 

 

 

 

 

Multiplicative

*

/

%

 

 

 

 

Arithmetic

+

++

– –

 

 

 

Relational

<

>

<=

>=

=

!=

 

Logical

||

&&

!

 

 

 

 

Assignment

:=

 

 

 

 

 

 

Miscellaneous

[ ]

,

( )

.

;

<#

#>

Table 60 briefly describes the action performed by each operator.

Table 60: Operator Actions

Operation

Operator

Action

Arithmetic (binary)

+

Adds the right and left sides together

Arithmetic (binary)

Subtracts the element to the right of the operator from the element to the left of the operator

Assignment

:=

Evaluates the elements to the right of the operator, then assigns that value to the local variable to the left of the operator

Combine

$

Creates a new string by joining the values of the right and left sides; converts any numeric values to strings before joining

Less than

<

Evaluates as true (returns a 1) if the element to the left of the operator is less than the expression to the right of the operator; otherwise the result is false (0)

Greater than

>

Evaluates as true (returns a 1) if the element to the left of the operator is greater than the expression to the right of the operator; otherwise the result is false (0)

Less than or equal to

<=

Evaluates as true (returns a 1) if the element to the left of the operator is less than or equal to the expression to the right of the operator; otherwise the result is false (0)

Greater than or equal to

>=

Evaluates as true (returns a 1) if the element to the left of the operator is greater than or equal to the expression to the right of the operator; otherwise the result is false (0)

Equal to

=

Evaluates as true (returns a 1) if the element to the left of the operator is equivalent to the expression to the right of the operator; otherwise the result is false (0)

Not equal to (logical NOT)

!=

Evaluates as true (returns a 1) if the element to the left of the operator is not equal to the expression to the right of the operator; otherwise the result is false (0)

Logical OR

||

Evaluates as true (returns a 1) if the values of either the left or right sides is nonzero; evaluation halts at the first true (1) expression

Logical AND

&&

Evaluates as true (returns a 1) if the values of the left and right sides are both nonzero; evaluation halts at the first false (0) expression

Miscellaneous

[ ]

See Invoking Other Macros for usage.

Miscellaneous

,

See While Constructs for usage.

Miscellaneous

( )

Groups operands and operators to achieve results different from simple precedence; effectively has the highest precedence

Miscellaneous

.

Provides access to environment commands; see Table 58. Provides access to macros; see Invoking Other Macros

Miscellaneous

;

Separates operation statements within a control expression

Miscellaneous

<# #>

Encloses control expressions

Multiplication

*

Multiplies the expression to the left of the operator by the expression to the right

Division

/

Divides the expression to the left of the operator by the expression to the right

Modulo

%

Divides the expression to the left of the operator by the expression to the right and returns the integer remainder. If the expression to the left of the operator is less than the expression to the right, then the result is the expression to the left of the operator.

Postincrement

++

Increments the variable after the expression is evaluated

Postdecrement

– –

Decrements the variable after the expression is evaluated

Preincrement

++

Increments the variable before the expression is evaluated

Predecrement

– –

Decrements the variable before the expression is evaluated

Negation

!

Reverses the logical state of its operand. 0 is returned for nonzero operands. 1 is returned for operands that evaluate to zero.

Arithmetic (unary)

+

Provides the absolute value of the value

Arithmetic (unary)

Provides the inverse of the value

Substring

substr()

Extracts a portion of a string

Randomize

rand()

Generates a random integer between the provided endpoints, inclusive

Round

round()

Rounds the value to the nearest integer

Truncate

truncate()

Truncates a noninteger value to the value left of the decimal point


[Contents] [Prev] [Next] [Index] [Report an Error]