iMachine¶
Returns integer information describing the computer’s arithmetic.
Synopsis¶
iMachine (n)
Required Arguments¶
- int
n
(Input) - Index indicating which value is to be returned. It must be between 0 and 12.
Return Value¶
The requested value is returned. If n
is out of range, NaN is returned.
Description¶
Function iMachine
returns information describing the computer’s
arithmetic. This can be used to make programs machine independent.
iMachine
(0) = Number of bits per byte
Assume that integers are represented in M-digit, base-A form as
where σ is the sign and \(0\leq x_k<A\) for \(k=0,\ldots,M\). Then,
n |
Definition |
---|---|
0 | C, bits per character |
1 | A, the base |
2 | \(M_s\), the number of base-A digits in a short int |
3 | \(A^{M_S}-1\), the largest short int |
4 | \(M_1\) the number of base-A digits in a long int |
5 | \(A^{M_l}-1\), the largest long int |
Assume that floating-point numbers are represented in N-digit, base B form as
where σ is the sign and \(0\leq x_k<B\) for \(k=1,\ldots,N\) and \(E_{min}\leq E\leq E_{max}\). Then
n |
Definition |
---|---|
6 | B, the base |
7 | \(N_f\), the number of base-B digits in float |
8 | \({E}_{\mathrm{min}_f}\), the smallest float exponent |
9 | \({E}_{\mathrm{max}_f}\), the largest float exponent |
10 | \(N_d\), the number of base-B digits in double |
11 | \({E}_{\mathrm{max}_f}\), the largest long int |
12 | \({E}_{\mathrm{max}_d}\), the number of base-B digits in double |
Example¶
In this example, all the values returned by iMachine
on a 32‑bit machine
with IEEE (Institute for Electrical and Electronics Engineer) arithmetic are
printed.
from __future__ import print_function
from pyimsl.stat.iMachine import iMachine
for n in range(0, 13):
ans = iMachine(n)
print("iMachine[", n, "] = ", ans)
Output¶
iMachine[ 0 ] = 8
iMachine[ 1 ] = 2
iMachine[ 2 ] = 15
iMachine[ 3 ] = 32767
iMachine[ 4 ] = 63
iMachine[ 5 ] = 9223372036854775807
iMachine[ 6 ] = 2
iMachine[ 7 ] = 24
iMachine[ 8 ] = -125
iMachine[ 9 ] = 128
iMachine[ 10 ] = 53
iMachine[ 11 ] = -1021
iMachine[ 12 ] = 1024