IMSL_MACHINE

Syntax | Return Value | Keywords | Discussion | Example | Version History

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

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

Syntax

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

Return Value

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

Keywords

DOUBLE

If present and nonzero, a structure containing the information describing the single-precision, floating-point arithmetic is returned.

FLOAT

If present and nonzero, a structure containing the information describing the single-precision, floating-point arithmetic is returned.

Discussion

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:

IMSL_MACHINE-08.jpg

where σ is the sign and 0 ≤ xk < A for k = 0, ..., M. Then, Table 25-4 describes the tags:

Table 25-4: Integer 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

IMSL_MACHINE-01.jpg, the largest short int

LONG_DIGITS

Ml, the number of base-A digits in a long int

MAX_LONG

IMSL_MACHINE-02.jpg, the largest long int

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

IMSL_MACHINE-09.jpg

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

Table 25-5: Floating Point Tags 

Tag
Definition

FLOAT_BASE

B, the base

FLOAT_DIGITS

Nf, the number of base-B digits in float

FLOAT_MIN_EXP

IMSL_MACHINE-03.jpg, the smallest float exponent

FLOAT_MAX_EXP

IMSL_MACHINE-04.jpg, the largest float exponent

DOUBLE_DIGETS

Nd, the number of base-B digits in double

DOUBLE_MIN_EXP

IMSL_MACHINE-05.jpg, the largest long int

DOUBLE_MAX_EXP

IMSL_MACHINE-06.jpg, 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:

IMSL_MACHINE-10.jpg

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

IMSL_MACHINE-11.jpg

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

IMSL_MACHINE-12.jpg

and:

IMSL_MACHINE-13.jpg

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 Table 25-6:

Table 25-6: Floating or Double Precision Tags

Tag
Definition

MIN_POS

BEminf  –1, the smallest positive number

MAX_POS

BEmaxf(1 – –Nf ), 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

IMSL_MACHINE-14.jpg

and:

IMSL_MACHINE-15.jpg

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_LONG	LONG	    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 

Version History

6.4

Introduced