Chapter 15: Utilities

machine (float)

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

Synopsis

#include <imsls.h>

float imsls_f_machine (int n)

The type double function is imsls_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, NaN is returned.

Description

Function imsls_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.

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 B = imsls_i_machine(6); Nf = imsls_i_machine(7);

and

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

Function imsls_f_machine is defined by the following table:

N

Definition

1

2

3

the smallest relative spacing

4

the largest relative spacing

5

log10(B)

6

NaN

7

Positive machine infinity

8

negative machine infinity

Function imsls_d_machine retrieves machine constants that define the computer’s double arithmetic. Note that for double B = imsls_i_machine(6), Nd = imsls_i_machine(10),

and

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

Example

In this example, all eight values returned by imsls_f_machine and by imsls_d_machine on a machine with IEEE arithmetic are printed.

#include <imsls.h>

main()
{
    int             n;
    float           fans;
    double          dans;

    for (n = 1;  n <= 8;  n++) {
        fans = imsls_f_machine(n);
        printf("imsls_f_machine(%d) = %g\n", n, fans);
    }

    for (n = 1;  n <= 8;  n++) {
        dans = imsls_d_machine(n);
        printf("imsls_d_machine(%d) = %g\n", n, dans);
    }
}

Output

imsls_f_machine(1) = 1.17549e-38
imsls_f_machine(2) = 3.40282e+38
imsls_f_machine(3) = 5.96046e-08
imsls_f_machine(4) = 1.19209e-07
imsls_f_machine(5) = 0.30103
imsls_f_machine(6) = NaN
imsls_f_machine(7) = Inf
imsls_f_machine(8) = -Inf
imsls_d_machine(1) = 2.22507e-308
imsls_d_machine(2) = 1.79769e+308
imsls_d_machine(3) = 1.11022e-16
imsls_d_machine(4) = 2.22045e-16
imsls_d_machine(5) = 0.30103
imsls_d_machine(6) = NaN
imsls_d_machine(7) = Inf
imsls_d_machine(8) = -Inf


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260