Data type and format


Workbench model and script are both strongly typed. This means that each variable has a fixed datatype, determined during compilation and cannot be changed during runtime. This allows for improved runtime code performance, stricter error checking leading to reduced runtime exceptions and well define memory allocation which is critical for many embedded applications.

Overview

There are seven datatypes that are supported which are listed below:

Datatype Size (in bits) Range
Double 64 ±1.797​693​134​862​315​70E​+308
Single 32 ±3.402​823​5E​+38
Long 64 -9,​223,​372,​036,​854,​775,​808 to +9,​223,​372,​036,​854,​775,​807
Integer 32 -2,​147,​483,​648 to +2,​147,​483,​647
Short 16/32 -32,​768 to +32,​767
Byte 8/32 0 to 255
Boolean 1/32/64 False or True

Numeric Type

Numeric data types consists of:

  1. Double - 64-bit IEEE floating point.

  2. Single - 32-bit IEEE floating point.

  3. Long - 64-bit fixed point integer.

  4. Integer - 32-bit fixed point integer.

  5. Short - 16-bit fixed point integer.

Short is 16-bit fixed point data but based on memory availablity, the 16-bit data may use a full 32-bit memory field with padded zeros or two Short variables might be packed as two consecutive 16-bit data in a 32-bit memory field. The data is automatically unpacked when needed and this does not alter results in anyway.

Non-numeric Type

Boolean values can be either True or False. These do not have any equivalent integral values to it. In most other pogramming languages, this data type is given an equivalent integral value; 1 if True, 0 if False or +ve value if True, -ve value if False or other finite values. Since models developed in Workbench can be translated to multiple commonly used programming languages, each with different interpretation of Boolean value, Workbench avoids assigning any intrinsic value to it. Similar to Short data type, Boolean may be bit-packed based on memory availability.

Byte represents a numeric value between 0 and 255 but unlike the numeric data types, it cannot be an operand of any arithmetic, comparison or bit-wise operation. These are solely intended for use in real-time data transfer or storage and for all other purposes, it must be typecasted to one of the numeric types.

Data type and format specifier

By default, all numbers without an explicit format specifier is assumed to be Double data type in Decimal format. To modify the type and format the number is qualified within the specifier operator |specifier|. The list of data type and format supported are listed below:

Format specifier

Format Specifier Example
Decimal d or D |d|3.3215
Hexadecimal h or H |h|8EF5
Binary b or B |b|110111011

Datatype specifier

Datatype Specifier Example
Double r or R |r|3.3215
Single f or F |f|3.3215
Long l or L |l|23432
Integer i or I |i|754
Short s or S |s|36

Data type and format can be mentioned together. For instance a Short number of value 58838 is declared in hex as |hs|E5D6, where h represents Hexadecimal data fromat and s represents Short data type. The order of the qualifier is irrevelant, i.e. |hs|E5D6 is identical to |sh|E5D6. The compiler will auto-correct it to format specifier followed by type specifier to maintian uniformity.

If the qualifier is not compatible with the data, then Error EC0001 - Unrecognized number format or out of range is thrown. Some of the possible wrong usage is shown below:

Examples Reason
|i|3.3 Floating-point number cannot be declared as integer.
|s|889563 Data size too long to fit within 16 bits.
|h|3.3 Data not in hexadecimal format.
|i|3E5 E-notation where 3E5 = 3x105, is supported only for floating-point data types.
|hr|454 Double data type cannot be represented in hexadecimal format.
|br|1101011.101101101 Double data type cannot be represented in binary format.

Typecast

All numeric data types can be implicitly casted. A variable of integer type can be assigned to variable of double type without any explicit cast operator. If the implicit conversion could lead to out of range data, then Warning WM0001 - Implicit datatype downcast is thrown. This warning can be avoided by using the Signal Conversion - Numeric Cast tool to cast between numeric data types. To cast from boolean to numeric data type, use the Signal Conversion - Boolean-Numeric Cast tool. The equivalent value for True and False can be set in this tool, since as mentioned earlier, unlike most other programming languages, Workbench does not associate any intrinsic value for Boolean type. To cast from numeric type to boolean, use the appropriate logical operator tool.



< Model routing methods : previous topic
next topic : Data collection >