machine

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

Synopsis

machine(n)

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 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 \(N_f\)-digit, base B form as

\[\sigma B^E \textstyle\sum_{k=1}^{N} x_k B^{-k}\]

where σ is the sign, \(0\leq x_k<B\) for \(k=1,2,\ldots,N_f\), and

\[E_{\min_f} \leq E \leq E_{\max_f}\]

Note that B = iMachine(6), \(N_f\) = iMachine(7),

\[E_{\min_f} = \mathrm{iMachine}(8)\]

and

\[E_{\max_f} = \mathrm{iMachine}(9)\]

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 machine(2) is returned for machine(6). On computers that do not have a special representation for infinity, machine(2) returns the same value as machine(7).

The function machine is defined by the following table:

n Definition
1 \(B^{E \min_f^{-1}}\), the smallest positive number
2 \(B^{E \max_f}\left( 1-B^{-Nf} \right)\), the largest number
3 \(B^{-N}_f\), the smallest relative spacing
4 \(B^{1-N_f}\), the largest relative spacing
5 \(log_{10}(B)\)
6 NaN (not a number)
7 positive machine infinity
8 negative machine infinity

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

\[E_{\min_f} = \mathrm{iMachine}(11)\]

and

\[E_{\max_f} = \mathrm{iMachine}(12)\]

Missing values in PyIMSL functions are always indicated by NaN (Not a Number). This is machine(6). 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 machine and by machine on a machine with IEEE arithmetic.

from __future__ import print_function
from pyimsl.math.machine import machine

for n in range(1, 9):
    dans = machine(n)
    print("machine[", n, "] = ", dans)

Output

machine[ 1 ] =  2.2250738585072014e-308
machine[ 2 ] =  1.7976931348623157e+308
machine[ 3 ] =  1.1102230246251565e-16
machine[ 4 ] =  2.220446049250313e-16
machine[ 5 ] =  0.30102998001990605
machine[ 6 ] =  nan
machine[ 7 ] =  inf
machine[ 8 ] =  -inf