Numeric and Logical Operators

Developers can combine numeric values and arithmetic operators to perform calculations. The following is a list of BBx numeric operators in order of precedence. BBx executes operators with the same precedence from left to right.

Operators Description Example

-

Unary Minus (Negation/Negative)

LET A=-B

^

Exponentiation (raise a number to an integer or non-integer power)

LET A=B^C

*

/

Multiplication and division

LET A=B*C, X=Y/Z

+

-

Addition and subtraction

LET A=B+C, X=Y-Z

<

>

=

<=

>=

<>

Relational Operators 

LET A=B<C, X=Y<>Z

AND

OR

Logical Operators

LET A=B OR C, X= Y AND Z

Use parentheses to change the order of execution of operators. PRO/5 supports at least 10 levels of parenthetic nesting (multi-line functions may reduce this), including array subscripts and function calls.

Arithmetic Operators: +, -, /, *, ^, -

Arithmetic Operator Description
-

Subtract, subtraction, minus, unary minus, negative, negation

Note that the unary minus operator (negative) takes the highest precedence, rather than being at the same precedence level of addition and subtraction. This means that in BBx, -2^2 = 4, because it is interpreted as (-2)^2, rather than as -(2^2), as it is in many other languages.

+ Add, plus, addition
* Multiply, times, multiplication
/ Divide, division
^ Exponent, power

Note that there is no modulo operator (%) in BBx. This functionality is provided by the MOD() Function - Decimal Modulo (Remainder).

Relational Operators: <, >, =, <=, >=, <>

Developers can use relational operators to compare two numeric values or two strings. The result of a logical comparison will be a boolean representing true or false. If the relation is true, the result is 1, and if it is false, the result is 0.

When comparing two numbers, their values round to the current precision during the comparison. See the PRECISION verb for more information.

When comparing two strings, their values are compared based on alphabetic order. A string that comes first alphabetically is evaluated as "less" than a string that comes later.

Operator Description
<

Less than

For strings, the less than operator returns true if the first string appears alphabetically before the second string.

> Greater than
=

Equal

Note that in BBx, the equals relational operator is only a single equals sign "=", and not a double equals "==", which is common in other languages.

<= Less than or equal
>= Greater than or equal
<>

Not equal

Note that in BBx, the not-equals relational operator is a combination of the less than and greater than operators "<>", rather than the "!=" common in other languages.

Example

 LET A= B<C, X=Y<>Z

Logical Operators: AND, OR

Note that the logical operators AND and OR have the same precedence level, rather than AND taking precedence, as is common in other languages.

Logical Operator Description
AND

The result of AND is 1 if both of its operands are nonzero, otherwise, the result is 0.

OR

The result of OR is 1 if either or both of its operands are nonzero, otherwise the result is 0.

BBx features short-circuit evaluation of the AND and OR operators. This means that the second value of the expression is only evaluated if necessary. For instance, if the first value of an AND expression is false, the second value will not be evaluated. Likewise, if the first value of an OR expression is true, the second value will not be evaluated.

Although BBx does not provide a NOT operator, the ! Operator - Invert Numeric Expression in BBj and the !() Function - Logical Not in PRO/5 can be used to invert the value of a logical or numeric expression.

Example

 LET A= B AND C, X=Y OR Z

See Also

!() Function - Logical Not

! Operator - Invert Numeric Expression

. Operator - Access Fields/Methods of Java Class Instances

MOD() Function - Decimal Modulo (Remainder)

BBj Object Operators

MOD() Function - Decimal Modulo (Remainder)