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
σM∑k=0xkAk
where σ is the sign and 0≤xk<A for k=0,…,M. Then,
n |
Definition |
---|---|
0 | C, bits per character |
1 | A, the base |
2 | Ms, the number of base-A digits in a short int |
3 | AMS−1, the largest short int |
4 | M1 the number of base-A digits in a long int |
5 | AMl−1, the largest long int |
Assume that floating-point numbers are represented in N-digit, base B form as
σBEN∑k=1xkB−k
where σ is the sign and 0≤xk<B for k=1,…,N and Emin≤E≤Emax. Then
n |
Definition |
---|---|
6 | B, the base |
7 | Nf, the number of base-B digits in float |
8 | Eminf, the smallest float exponent |
9 | Emaxf, the largest float exponent |
10 | Nd, the number of base-B digits in double |
11 | Emaxf, the largest long int |
12 | Emaxd, 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