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, NaN is returned.
Description¶
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.
Assume that float numbers are represented in \(N_f\)-digit, base B form as
where σ is the sign; \(0\leq x_k<B\) for \(k=1,2,\ldots,N_f\); and
Note that B = iMachine
(6); \(N_f\) = iMachine
(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 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).
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^{-N_f} \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 |
7 | Positive machine infinity |
8 | negative machine infinity |
Function machine
retrieves machine constants that define the computer’s
double arithmetic. Note that for double B = iMachine
(6),
\(N_d\) = iMachine
(10),
and
Missing values in functions are always indicated by NaN. 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¶
In this example, all eight values returned by machine
and by machine
on a machine with IEEE arithmetic are printed.
from __future__ import print_function
from pyimsl.stat.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