ANY-maze Help > The ANY-maze reference > The Protocol page > The elements of a protocol > Testing > Procedures > Elements of a procedure > Maths functions and operators

Maths functions and operators

Introduction

ANY-maze includes a number of mathematical functions and operators that allow a procedure to perform calculations.

These functions and operators all take one or two parameters, i.e. values that are used by the function or operator. For example, the + operator takes two parameters (the two values that are being added together) and the Sqrt function takes one parameter (the value whose square root is being calculated).

  
Function/Operator  No. parameters Description
+       2                Gives the result of adding the left-hand parameter to the right-hand parameter.
-       2                Gives the result of subtracting the right-hand parameter from the left-hand parameter.
x       2                Gives the result of multiplying the left-hand parameter by the right-hand parameter.
/       2                Gives the result of dividing the left-hand parameter by the right-hand parameter.
Mod     2                Gives the remainder, when the left-hand parameter is divided by the right-hand parameter.
Sqrt    1                Gives the square root of the parameter.
Pow     2                Gives the first parameter to the Nth power, where N is the second parameter.
Abs     1                Gives the absolute value of the parameter, i.e. if the parameter is negative, it returns the value with the negative sign removed.
Log     1                Gives the base 10 logarithm of the parameter.
Ln      1                Gives the natural logarithm (base e) of the parameter.
Sin     1                Gives the sine of the parameter, which is assumed to be an angle in degrees.
Cos     1                Gives the cosine of the parameter, which is assumed to be an angle in degrees.
Tan     1                Gives the tangent of the parameter, which is assumed to be an angle in degrees.
Sin-1   1                Gives the inverse sine of the parameter, i.e. the angle for which the parameter is the sine.
Cos-1   1                Gives the inverse cosine of the parameter, i.e. the angle for which the parameter is the cosine.
Tan-1   1                Gives the inverse tangent of the parameter, i.e. the angle for which the parameter is the tangent.
Round   2                Rounds the first parameter to the number of decimal places specified by the second parameter.
Random  2                Generates a random number between the values specified by the two parameters. The second parameter must be greater than the first parameter.
 To randomise the contents of an array, see the Randomise array statement in the Other statements topic.  

Example

The following section taken from a procedure uses some of the operators and functions listed above to perform a simple calculation of distance, using built-in variables for the animal's current centre point X and Y, and user-defined variables to aid in the calculation. These user-defined variables have been noted from the animal's centre point earlier in the procedure.

  

  

Figure 1. This example uses the +, - and x operators, together with the Sqrt function, to calculate a distance.

More information

The parameters to mathematical functions and operators can either be simple numeric values, or they can be any expression that evaluates to a numerical value (for example, another mathematical function from the list above).

If any of the parameters of one of these mathematical functions evaluates to #N/A, the result of the function will also be #N/A.

You will often want to use the value of a User-defined variable as a parameter to one of these functions, but since the procedure editor doesn't know what the value of a variable will be until it runs, it is quite possible that when the procedure tries to evaluate the mathematical operator or function, the variable does not contain a numerical value.

If a non-numerical value is passed to one of these mathematical functions or operators, it will evaluate as #N/A. This is shown in figure 2.

  

  

Figure 2. This section of a procedure is valid to write, but the values that are used in the + operator are the text "Hello" and the constant True. These can't be added together, so the + operator evaluates to #N/A, and the text displayed on the screen is "#N/A". A warning will also be generated.

Where possible, ANY-maze will try and evaluate a variable as a numerical value for all the functions and operators listed above. If the variable contains True or False, it will evaluate to 1 or 0 respectively. If it contains text, then the procedure can only successfully extract a numerical value if the text is obviously a number, for example '5' or '-1.234'

In the example above, if the 'parameter 1' variable were set to False, then the + operator would evaluate to True + False, i.e. 1 + 0, so the value assigned to the 'Result' variable would be 1.

  

A common mistake when entering parameters to functions like this is to type in the name of the variable, rather than dragging the variable into the procedure. If you do this, you'll get an error like the following:

  

  

Figure 3. A procedure statement where the name of the variable has been typed into a + operator, rather than dragging in the variable from elsewhere. A warning message is shown.

  

If you've used one of the mathematical operators (+, -, x or /) and you realise you need to change the one you're using, (for example, you want to change x to +), just right-click on the operator in the procedure editor. You'll get a drop-down menu which includes the Change operator option; selecting the new operator will change the operator while leaving both of its parameters intact.

© Copyright 2003-2026 Stoelting Co. All rights reserved

ANY-maze help topic T0497