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

SUB

Script Function: It performs a subtraction

Syntax

SUB(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

The result of the subtraction.

Comments

This script function subtracts Operand2 from Operand1.

Operand1 and Operand2 must be expressions which correspond to numbers in the allowed value range of the data types. The result must not exceed this range. The Operand2 must not be zero.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 elementl :DEFINE.  

 

The result's data type is decisive and not the operand's data type. A negative Operand2 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.

Example

The following example stores the result of the arithmetic operation in a script variable. Operand1 and Operand2 are specified as numeric expressions.

:SET &RESULT# = SUB(1000,999)

The following example shows a subtraction with floating-point numbers. 

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

The following result is output in the activation protocol:

U0020408 +0000000000000015.7600000000000000

Another Way to Perform Subtraction

Another way to perform subtraction is shown below. In this example, the value of a script variable is set to the result of 3 minus 2.

:SET &SUBTRACT# = 3 - 2
:
P &SUBTRACT#

The following result is output in the activation protocol:

U0020408 0000000000000001

 

See also:

Script element Description

ADD

Performs an addition
MULT Performs a multiplication
MOD Returns the remainder of a division
DIV Performs a division
RANDOM Generates random numbers

Script Elements - Arithmetics

About Scripts
Script Elements - Alphabetical Listing

Script Elements - Ordered by function