LONG Function

The LONG function has two forms that perform the following actions:

  • Converts an expression to longword integer data type.

  • Extracts data from an expression and places it in a longword integer scalar or array.

enabled.

Usage

This form is used to convert data.

    result = LONG(expr)

This form is used to extract data.

    result = LONG(expr, offset, [dim1, ... , dimn ])

Input Parameters

To convert data:

expr—The expression to be converted.

To extract data:

expr—The expression from which to extract data.

offset—The offset, in bytes, from the beginning of expr to where the extraction is to begin.

dimi—(optional) The dimensions of the result. The dimensions may be any scalar expression with up to eight dimensions specified.

Returned Value

For data conversion:

result—A copy of expr converted to longword integer data type.

For data extraction:

result—If offset is used, LONG does not convert result, but allows fields of data extracted from expr to be treated as longword integer data. If no dimensions are specified, the result is scalar.

Keywords

None.

Discussion

Conversion usage:

If the values of expr are not within the range of a long integer, a misleading result occurs and a message may be displayed.

For example, on a 32-bit system suppose A = 2.0 ^ 31 + 2. The following commands,

B = LONG(A) 
C = LONG(–A)

produce the erroneous results of

B = 2147483647
C = –2147483648

In addition, PV‑WAVE does not check for overflow during conversion to longword integer data type.

Example

In this example, LONG is used in two ways. First, LONG is used to convert a single-precision, floating-point array to type longword. Next, LONG is used to extract a subarray from the longword array created in the first step.

; Create single-precision, floating-point vector of length 6.
; Each element has a value equal to its one-dimensional
; subscript plus 0.5.
a = FINDGEN(6) + 0.5
PRINT, a
; PV-WAVE prints:
; 0.500000 1.50000 2.50000 3.50000 4.50000 5.50000
; Convert a to type longword.
b = LONG(a)
; Note that floating-point numbers in a were truncated by LONG.
INFO, b
; PV-WAVE prints: VARIABLE     LONG      = Array(6)
PRINT, b
; PV-WAVE prints: 0    1    2    3    4    5
; Extract the last four elements of b, and place them in c.
; On 64-bit systems, the second, offset argument would be '16'
c = LONG(b, 8, 2, 2)
INFO, c
; PV-WAVE prints: 
; VARIABLE     LONG      = Array(2, 2)
PRINT, c
; PV-WAVE prints:
;   2         3
;   4         5

See Also

BYTE, COMPLEX, DOUBLE, FIX, FLOAT, LINDGEN, LONARR

For more information on data extraction, see the PV‑WAVE Programmer’s Guide.