# &abs(4)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

&abs, &add, &sub, &mul, &div, &mod, &neg, &inc, &dec, &pinc, &pdec - Numeric macro operators

## SYNOPSIS

&abs num1
&add num1 num2
&sub num1 num2
&multiply num1 num2
&divide num1 num2
&mod num1 num2
&negate num

&inc variable increment
&dec variable decrement
&pinc variable increment
&pdec variable decrement

## DESCRIPTION

The numeric operators operate on variables or integers to perform integer computations, returning the integer result of the operation. The contents of the variables are interpreted as signed integers typically with a dynamic range of 2^31 <= num <= 2^31-1.

The operators may all be abbreviated to their three letter abbreviation (i.e. &multiply may be expressed as &mul). In all cases the first argument is completely evaluated before the second argument.

&abs num1

Returns the absolute value of num1 i.e. if num1 is positive it returns num1, else -num1

&add num1 num2

Addition of two numbers num1 and num2. i.e. num1 + num2

&sub num1 num2

Subtract the second number num2 from the first num1 i.e. num1 - num2.

&multiply num1 num2

(Signed) Multiply num1 by num2. i.e. num1 * num2. &mul is the three letter abbreviation.

&div num1 num2

Divide the first number num1 by the second num2, returning the integer result. i.e. num1 / num2. &div is the three letter abbreviation.

&mod num1 num2

Divide the first number num1 by the second num2, returning the integer remainder. i.e. num1 % num2.

&negate num

Negate the integer (multiply by -1) i.e. -num. &neg is the three letter abbreviation.

Expression evaluation is prefix. Operators may be nested using a pre-fix ordering, there is no concept of brackets (in-fix notation). The expression `(2 * 3) + 4` is expressed as:-

    &add &mul 2 3 4

conversely `2 * (3 + 4)` is expressed as:-

    &mul 2 &add 3 4

The pre/post incrementing and decrementing operators provide a mechanism for stepping through indexed information without incurring the overhead of providing multiple statements to perform assignment operations. The variable argument MUST be the name of a variable, it cannot be an expression or an indirection. The increment may be any integer expression (including another auto (dec)increment). Note that variable is re-assigned with it's new value within the operator, therefore use with care when performing multiple (dec)increments within the same statement line. The four operators are defined as follows:

&inc variable increment

Pre-increment the variable by increment, returning the incremented value i.e. variable += increment.

&dec variable decrement

Pre-decrement the variable by decrement, returning the decrement value i.e. variable -= decrement.

&pinc variable increment

Post-increment the variable by increment, returning the pre-increment value i.e. variable++., where the ++ value is determined by increment. The return value is the value of variable as passed by the caller, the next reference to variable uses the variable+increment value.

&pdec variable decrement

Post-decrement the variable by decrement, returning the pre-decrement value i.e. variable--, where the -- value is determined by decrement.

## EXAMPLE

Add two numbers together and assign to a variable:-

    set-variable %result &add %num1 %num2

Increment `%result` by 1 and add to `%result2`

    set-variable %result  &add %result 1
    set-variable %result2 &add %result2 %result

The previous example could have used the increment operators to achieve the same result in a single operation e.g.

    set-variable %result2 &add %result2 &inc %result 1

## SEE ALSO

Variable Functions, &great(4).

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>