Automation Engine Script Guide > Ordered by Function > Arithmetics > ADD

ADD

Script Function: It performs an addition.

Syntax

ADD(Operand1, Operand2)

Syntax

Description/Format

Operand1

The first expression.
Format: script literal, script variable or number specified without quotation marks.

Operand2

The second expression.
Format: script literal, script variable or number specified without quotation marks.


Return code

Result of the addition

Comments

Adds Operand1 to Operand2. The values that are returned are 16-digit alphanumeric terms (strings) with leading zeros.

Operand1 and Operand2 must be expressions that correspond to numbers in the allowed value range of the data types. The result must not exceed this range.

You can assign the result to a script variable but it must show the corresponding data type. Any attempt to store a negative number to a variable of the data type "unsigned" results in an error. If the result is a floating-point number and the target variable is of data type "signed" or "unsigned", the decimal positions are truncated. The data type "float" supports negative numbers and floating-point numbers. The data type "string" can also be used. In this case, the result is stored as a string instead of a number. The data type of script variables can be defined by using the script element DEFINE

The result's data type is decisive and not the operand's data type. A negative and a positive operand can result in a positive number which can then be stored in a target variable of the data type "unsigned".

Note that arithmetic operations using floating-point numbers can supply inexact results.

The result is returned in the 16-digit default format. Floating-point numbers also include 16 decimal places and an algebraic sign (+ or -) is used as the first sign if negative numbers are supported. Formatting can be changed by using the script function FORMAT.

Examples

The first example stores the arithmetic operation's result in a script variable. Operand1 and Operand2 are numeric expressions.

:SET &RESULT# = ADD(1000,333)

The second example uses this script function in order to define a condition.

:SET &MAXIMUM# = 3000
:
SET &RUN1# = 5000
:
SET &RUN2# = 2000 
!...

:
IF ADD(&RUN1#,&RUN2#) > &MAXIMUM#  
!...
 
:
ENDIF

The following example adds up two floating-point numbers.

:DEFINE &RESULT#,float
:SET &RESULT#ADD(10.31,-5.45)
:P &RESULT#

The following result is output in the activation protocol:

U0020408 +0000000000000004.8600000000000000

Another Way to Perform Addition

Another way to perform addition is shown below. In this example, the value of a script variable is set to the sum of 1 plus 1.

:SET &ADD# = 1 + 1
:
P &ADD#

The following result is output in the activation protocol:

U0020408 0000000000000002

 

See also:

Script element Description

SUB

Performs a subtraction.
MULT Performs a multiplication.
DIV Performs a division.
MOD Returns the remainder of a division.
RANDOM Generates random numbers.

Script Elements - Arithmetics

About Scripts
Script Elements - Alphabetical Listing

Script Elements - ordered by function