IMSL_MACHINE

The IMSL_MACHINE function returns information describing the computer’s arithmetic.

This routine requires an IDL Advanced Math and Stats license. For more information, contact your sales or technical support representative.

The IMSL_MACHINE function returns information describing the computer’s arithmetic. This can be used to make programs machine independent. The information returned by IMSL_MACHINE is in the form of a structure. A different structure is used for each type: integer, float, and double. Depending on how IMSL_MACHINE is called, a different structure is returned.

The default action of IMSL_MACHINE is to return the structure IMACHINE which contains integer information on the computer’s arithmetic. By using either the keywords Float or Double, information about the floating- or double-precision arithmetic is returned in structures FMACHINE or DMACHINE.

The contents of the these structures are described below.

Integer Information: IMACHINE

Assume that integers are represented in M-digit, base A form as:

where σ is the sign and 0 ≤ xk < A for k = 0, ..., M. Then, the table below describes the tags:

Tag Definition
BITS_PER_CHAR C, bits per character
INTEGER_BASE A, the base
INTEGER_DIGITS Ms, the number of base-A digits in a short int
MAX_INTEGER – 1, the largest short int
LONG_DIGITS Ml, the number of base-A digits in a long int
MAX_LONG – 1, the largest long int

Assume that floating-point numbers are in N-digit, base B form as:

where σ is the sign and 0 ≤ xk < B for k = 1, ..., N for and Emin ≤ E ≤ Emax. Then, the table below describes the tags:

Tag

Definition

FLOAT_BASE

B, the base

FLOAT_DIGITS

Nf, the number of base-B digits in float

FLOAT_MIN_EXP

, the smallest float exponent

FLOAT_MAX_EXP

, the largest float exponent

DOUBLE_DIGETS

Nd, the number of base-B digits in double

DOUBLE_MIN_EXP

, the largest long int

DOUBLE_MAX_EXP

, the number of base-B digits in double

Floating- and Double-precision Information: FMACHINE and DMACHINE

Information concerning the floating- or double-precision arithmetic of the computer is contained in the structures FMACHINE and DMACHINE. These structures are returned into named variables by calling IMSL_MACHINE with the keywords Float for FMACHINE and Double for DMACHINE.

Assume that float numbers are represented in Nf- digit, base B form as:

where σ is the sign, 0 ≤ xk < B for k = 1, 2, ..., Nf and

≤ E ≤

Note that if we make the assignment imach = IMSL_MACHINE( ), then B = imach.FLOAT_BASE, Nf = imach.FLOAT_DIGITS,

= imach.FLOAT_MIN_EXP

and:

= imach.FLOAT_MAX_EXP

The ANSI/IEEE 754-1985 standard for binary arithmetic uses NaN (Not a Number) as the result of various otherwise illegal operations, such as computing 0/0. If the assignment amach = IMSL_MACHINE(/FLOAT) is made, then on computers that do not support NaN, a value larger than amach. MAX_POS is returned in amach.NAN. On computers that do not have a special representation for infinity, amach.POS_INF contains the same value as amach.MAX_POS.

The structure IMACHINE is defined by the table below:

Tag

Definition

MIN_POS

, the smallest positive number

MAX_POS

, the largest number

MIN_REL_SPACE

B – Nf, the smallest relative spacing

MAX_REL_SPACE

B1 – Nf, the largest relative spacing

LOG10_BASE

log10(B)

NAN

NaN

POS_INF

positive machine infinity

NEG_INF

negative machine infinity

The structure DMACHINE contains machine constants that define the computer’s double arithmetic. Note that for double, if the assignment imach = IMSL_MACHINE( ) is made, then:

B = imach.FLOAT_BASE, Nf = imach.DOUBLE_DIGITS

= imach.DOUBLE_MIN_EXP

and:

= imach.DOUBLE_MAX_EXP

Missing values in IDL Advanced Math and Stats procedures and functions are often indicated by NaN. There is no missing-value indicator for integers. Users usually have to convert from their missing value indicators to NaN.

Example

In this example, all values returned by IMSL_MACHINE are printed on a machine with IEEE (Institute for Electrical and Electronics Engineering) arithmetic.

i = IMSL_MACHINE()

f = IMSL_MACHINE(/FLOAT)

d = IMSL_MACHINE(/DOUBLE)

; Call HELP with the keyword STRUCTURE set to view the contents

; of the structures.

HELP, i, f, d, /STRUCTURE

 

** Structure IMACHINE, 13 tags, length=52:

BITS_PER_CHAR LONG 8

INTEGER_BASE LONG 2

INTEGER_DIGITS LONG 15

MAX_INTEGER LONG 32767

LONG_DIGITS LONG 31

MAX_LONGLONG 2147483647

FLOAT_BASE LONG 2

FLOAT_DIGITS LONG 24

FLOAT_MIN_EXP LONG -125

FLOAT_MAX_EXP LONG 128

DOUBLE_DIGITS LONG 53

DOUBLE_MIN_EXP LONG -1021

DOUBLE_MAX_EXP LONG 1024

** Structure FMACHINE, 8 tags, length=32:

MIN_POS FLOAT 1.17549e-38

MAX_POS FLOAT 3.40282e+38

MIN_REL_SPACE FLOAT 5.96046e-08

MAX_REL_SPACE FLOAT 1.19209e-07

LOG_10 FLOAT 0.301030

NAN FLOAT NaN

POS_INF FLOAT Inf

NEG_INF FLOAT -Inf

** Structure DMACHINE, 8 tags, length=64:

MIN_POS DOUBLE 2.2250739e-308

MAX_POS DOUBLE 1.7976931e+308

MIN_REL_SPACE DOUBLE 1.1102230e-16

MAX_REL_SPACE DOUBLE 2.2204460e-16

LOG_10 DOUBLE 0.30102998

NAN DOUBLE NaN

POS_INF DOUBLE Infinity

NEG_INF DOUBLE -Infinity

Syntax

Result = IMSL_MACHINE( [, /DOUBLE] [, /FLOAT])

Return Value

The information describing the computer’s arithmetic is returned in a structure.

Arguments

None

Keywords

DOUBLE (optional)

The information describing the computer’s arithmetic is returned in a structure.

FLOAT (optional)

The information describing the computer’s arithmetic is returned in a structure.

Version History

6.4

Introduced