machine (float)

Returns information describing the computer’s floating-point arithmetic.

Synopsis

#include <imsl.h>

float imsl_f_machine(int n)

The type double function is imsl_d_machine.

Required Arguments

int n (Input)
Index indicating which value is to be returned.The index must be between 1 and 8.

Return Value

The requested value is returned. If n is out of range, then NaN is returned.

Description

The function imsl_f_machine returns information describing the computer’s floating-point arithmetic. This can be used to make programs machine independent. In addition, some of the functions are also important in setting missing values (see below).

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

 

 

Note that Bimsl_i_machine(6),  Nf = imsl_i_machine(7),

 

and

 

 

The ANSI/IEEE Std 754-1985 standard for binary arithmetic uses NaN (not a number) as the result of various otherwise illegal operations, such as computing 0/0. On computers that do not support NaN, a value larger than imsl_d_machine(2) is returned for imsl_f_machine(6). On computers that do not have a special representation for infinity, imsl_f_machine(2) returns the same value as imsl_f_machine(7).

The function imsl_f_machine is defined by the following table:

n

Definition

1

, the smallest positive number

2

, the largest number

3

, the smallest relative spacing

4

, the largest relative spacing

5

log10(B)

6

NaN (not a number)

7

positive machine infinity

8

negative machine infinity

The function imsl_d_machine retrieves machine constants which define the computer’s double arithmetic. Note that for double B = imsl_i_machine(6), Nd = imsl_i_machine(10),

 

and

 

Missing values in IMSL functions are always indicated by NaN (Not a Number). This is imsl_f_machine(6) in single precision and imsl_d_machine(6) in double. There is no missing-value indicator for integers. Users will almost always have to convert from their missing value indicators to NaN.

Example

This example prints all eight values returned by imsl_f_machine and by imsl_d_machine on a machine with IEEE arithmetic.

 

#include <imsl.h>

#include <stdio.h>

 

int main()

{

int n;

float fans;

double dans;

 

for (n = 1; n <= 8; n++) {

fans = imsl_f_machine(n);

printf("imsl_f_machine(%d) = %g\n", n, fans);

}

 

for (n = 1; n <= 8; n++) {

dans = imsl_d_machine(n);

printf("imsl_d_machine(%d) = %g\n", n, dans);

}

}

Output

 

imsl_f_machine(1) = 1.17549e-38

imsl_f_machine(2) = 3.40282e+38

imsl_f_machine(3) = 5.96046e-08

imsl_f_machine(4) = 1.19209e-07

imsl_f_machine(5) = 0.30103

imsl_f_machine(6) = NaN

imsl_f_machine(7) = Inf

imsl_f_machine(8) = -Inf

imsl_d_machine(1) = 2.22507e-308

imsl_d_machine(2) = 1.79769e+308

imsl_d_machine(3) = 1.11022e-16

imsl_d_machine(4) = 2.22045e-16

imsl_d_machine(5) = 0.30103

imsl_d_machine(6) = NaN

imsl_d_machine(7) = Inf

imsl_d_machine(8) = -Inf