|
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
IntroductionANY-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).
ExampleThe 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 informationThe 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 |