MACHINE Function

Returns information describing the computer’s arithmetic.

Usage

result = MACHINE( )

Returned Value

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

Output Keywords

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

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

Discussion

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

The default action of 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 s is the sign and 0 £ xk < A for k = 0, ..., M. Then, Integer Tags describes the tags:

 

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

, the largest short int

LONG_DIGITS

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

MAX_LONG

, the largest long int

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

 

where s is the sign and 0 £ xk < B for k = 1, ..., N for and Emin £ E £ Emax. Then, Floating Point Tags describes the tags:

 

Floating Point 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 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 s is the sign, 0 £ xk < B for k = 1, 2, ..., Nf  and

 

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

 

and:

 

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 = 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 Floating or Double Precision Tags:

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 = MACHINE( ) is made, then:

B = imach.FLOAT_BASE, Nf = imach.DOUBLE_DIGITS

 

and:

 

Missing values in PV‑WAVE Advantage procedures and functions are often indicated by NaN. There is no missing-value indicator for integers. Users ususally have to convert from their missing value indicators to NaN.

Example

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

i = machine()
f = machine(/Float)
d = machine(/Double)
; Call INFO with the keyword Structure set to view the 
; contents of the structures.
INFO, 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