In IDL there are twelve basic, atomic data types, each with its own form of constant. The data type assigned to a variable is determined either by the syntax used when creating the variable, or as a result of some operation that changes the type of the variable. IDL's basic data types are discussed in more detail beginning with Defining and Using Constants.
In addition, IDL provides several compound data types that serve as containers for variables of other data types. Examples of compound data types include pointers, structures, objects, lists, and hashes. You cannot create a constant of a compound data type, but it is generally possible to create an “empty” variable of a compound data type. See Compound Data Types for additional information.
Finally, there is the special !NULL system variable, which represents an undefined variable.
The following table lists IDL's data types, provides examples of how to explicitly create a variable of each type, and list the routines used to create variables and arrays of each type. Type codes shown in the Type Code column correspond to the type code returned by the SIZE function. Type names shown in the Type Name column correspond to the string returned by the TYPENAME function.
Data Type |
Description |
Type Code |
Type Name |
Creation |
Routines |
Null |
An undefined variable. !NULL may be used for array concatenation, array indexing, and for comparison. |
0 |
UNDEFINED |
a = !NULL
a = [ ]
a = { }
|
!NULL
|
Byte
|
An 8-bit unsigned integer ranging in value from 0 to 255. Pixels in images are commonly represented as byte data.
|
1 |
BYTE |
a = 5B
a = BYTE(5)
|
BYTE
BYTARR
|
Integer
|
A 16-bit short signed integer ranging from –32,768 to +32,767.
|
2 |
INT |
b = 0 (see below)
b = 0S
b = FIX(0)
|
FIX
INTARR
|
Unsigned Integer
|
A 16-bit short unsigned integer ranging from 0 to 65535.
|
12 |
UINT |
c = 0U (see below)
c = 0US
c = UINT(0)
|
UINT
UINTARR
|
Long
|
A 32-bit long signed integer ranging in value from –2 147 483 648 to +2 147 483 647.
|
3 |
LONG |
d = 0L
d = LONG(0)
|
LONG
LONARR
|
Unsigned Long
|
A 32-bit long unsigned integer ranging in value from 0 to 4 294 967 295.
|
13 |
ULONG |
e = 0UL
e = ULONG(0)
|
ULONG
ULONARR
|
64-bit Long
|
A 64-bit signed integer ranging in value from –9 223 372 036 854 775 808 to +9 223 372 036 854 775 807.
|
14 |
LONG64 |
f = 0LL
f = LONG64(0)
|
LONG64
LON64ARR
|
64-bit Unsigned Long
|
A 64-bit unsigned integer ranging in value from 0 to 18 446 744 073 709 551 615.
|
15 |
ULONG64 |
g = 0ULL
g = ULONG64(0)
|
ULONG64
ULON64ARR
|
Floating-point
|
A 32-bit, single-precision, floating-point number in the range of ±1038, with approximately six or seven significant digits.
|
4 |
FLOAT |
h = 0.0
h = FLOAT(0)
|
FLOAT
FLTARR
|
Double-precision
|
A 64-bit, double-precision, floating-point number in the range of ±10308 with approximately 15 or 16 significant digits.
|
5 |
DOUBLE |
i = 0.0D
i = DOUBLE(0)
|
DOUBLE
DBLARR
|
Complex
|
A real-imaginary pair of single-precision, floating-point numbers. Complex numbers are useful for signal processing and frequency domain filtering.
|
6 |
COMPLEX |
j = COMPLEX(1.0, 0.0)
j = COMPLEX(1,0)
|
COMPLEX
COMPLEXARR
|
Double-precision complex
|
A real-imaginary pair of double-precision, floating-point numbers.
|
9 |
DCOMPLEX |
k = DCOMPLEX(1.0, 0.0)
|
DCOMPLEX
DCOMPLEXARR
|
String
|
A sequence of characters, from 0 to 2 147 483 647 (2.1 GB) characters in length, which is interpreted as text.
|
7 |
STRING |
l = 'Hello'
l = STRING([72B, 101B,
108B, 108B, 111B])
|
STRING
STRARR
|
Structure
|
A compound data type that contains pairs of tags and values, where the values can be of any data type. Once a structure is created, neither the tags nor the data types of the values associated with the tags can be changed.
|
8 |
Structure name or ANONYMOUS |
s = {name,tag:0b}
s = Create_Struct('tag1', 0.0, 'tag2', 'hello')
|
CREATE_STRUCT
|
Pointer
|
A compound data type that contains a reference to a single value, where the value can be of any data type. The data type of the value referred to can be changed.
|
10 |
POINTER |
p = PTR_NEW(0b)
|
PTR_NEW
|
Object
|
A compound data type that contains a reference to an instance of an IDL object class. Object instances can contain data of any type, but the data types allowed are defined by the object class and cannot be changed after creation.
|
11 |
Class name or OBJREF (for null objects) |
o = OBJ_NEW('class')
|
OBJ_NEW
|
List
|
A compound data type that contains a reference to a collection of values. The individual values can be of any data type, and the data types and values can be changed.
|
11 |
LIST |
l = LIST(1,2)
|
LIST
|
Hash |
A compound data type that contains a reference to a collection of key-value pairs. The key can be of any scalar type, and the value can be of any type. The data types and values can be changed. |
11 |
HASH |
h = HASH('Id', 1234) |
HASH
|
Dictionary |
A hash whose keys are case-insensitive strings that must be valid variable names. The key/value pairs can be accessed using "dot" notation. |
11 |
DICTIONARY |
d = DICTIONARY('key', 1234) |
DICTIONARY
|
Ordered Hash |
A hash which preserves the order of the key/value pairs. |
11 |
ORDEREDHASH |
o = ORDEREDHASH('A',1,'B',2) |
ORDEREDHASH
|
Short Integers and the DEFINT32 Compile Option
By default, integers in the range -32767 to 32767 will automatically be defined as type INT (16 bits) and you can omit the "s" type specifier. If the DEFINT32 (or IDL2) compile option is turned on, then by default any integer constants will be 32-bit integers and you need to use the "s" or "us" to force IDL to create 16-bit integers. For example:
IDL> help, 1234, 1234u
<Expression> INT = 1234
<Expression> UINT = 1234
IDL> compile_opt DEFINT32
IDL> help, 1234, 1234u
<Expression> LONG = 1234
<Expression> ULONG = 1234
IDL> help, 1234s, 1234us
<Expression> INT = 1234
<Expression> UINT = 1234
Floating-point Values and the FLOAT64 Compile Option
By default, floating-point numbers without the "d" type specifier will be type FLOAT (32 bits). If the FLOAT64 (or IDL3) compile option is turned on, then by default any floating-point constants will be type DOUBLE (64 bits). You can always use the "e" (exponent) type specifier to force the constant to be type FLOAT. For example:
IDL> help, 2459810.8580208337, /full
<Expression> FLOAT = 2459810.8
IDL> compile_opt float64
IDL> help, 2459810.8580208337, /full
<Expression> DOUBLE = 2459810.8580208337
IDL> help, 2459810.8580208337e, /full
<Expression> FLOAT = 2459810.8
Precision of Floating-Point Numbers
The precision of IDL's floating-point numbers depends on the platform and compiler. The values shown here are minimum values; in some cases, IDL may deliver slightly more precision than we have indicated. If your application uses numbers that are sensitive to floating-point truncation or round-off errors, or values that cannot be represented exactly as floating-point numbers, this is something you should consider.
For more information on floating-point mathematics, see Accuracy and Floating Point Operations. For information on your machine's precision, see MACHAR.