[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.2.6.1 Arithmetic Operations

Radtest provides the common arithmetic operators, which follow normal precedence rules (see section Operator Precedence (How Operators Nest)), and work as you would expect them to. The only notable exception is subtraction operator (minus) which can be used as part of a variable or attribute name, and therefore expressions like $x-3 are ambiguous. This expression can be thought of either as a dereference of the variable x-3 (see section Dereferencing Variables), or as subtraction of the value 3 from the value of the variable x. Radtest always resolves this ambiguityin the favor of variable dereference. Therefore we advise you to always surround minus sign by whitespace, if it is used as a subtraction operator. So, instead of $x-3, write $x - 3. For other methods of solving this ambiguity, See minus-ambiguity.

This table lists the arithmetic operators in order from highest precedence to lowest:

- x

Negation.

+ x

Unary plus. This is equivalent to x.

x * y

Multiplication.

x / y

Division.

x % y

Remainder.

x + y

Addition.

x - y

Subtraction.

Unary plus and minus have the same precedence, the multiplication, division and remainder all have the same precedence, and addition and subtraction have the same precedence.

If x and y are of different data types, their values are first coerced to a common data type, selected using a set of rules (see section Conversion Between Data Types).


This document was generated by Sergey Poznyakoff on December, 6 2008 using texi2html 1.78.