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, then NaN is returned.

Description

The 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

σMk=0xkAk

where σ is the sign and 0xk<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 AMs1, the largest short int
4 Ml, the number of base-A digits in a long int
5 AM11, the largest long int

Assume that floating-point numbers are represented in N-digit, base B form as

σBENk=1xkBk

where σ is the sign and 0xk<B for k=1,,N for and E_$\leq E\leq E_".

Then,

n Definition
6 B, the base
7 N_f, the number of base-B digits in float
8 E_{\min_f},\text{the smallest } \mathit{float} \text{ exponent}
9 E_{\max_f},\text{the largest } \mathit{float} \text{ exponent}
10 N_d, the number of base-B digits in double
11 E_{\min_d},\text{the smallest } \mathit{double} \text{ exponent}
12 E_{\max_d},\text{the largest } \mathit{double} \text{ exponent}

Example

This example prints all the values returned by iMachine on a 32-bit machine with IEEE (Institute for Electrical and Electronics Engineer) arithmetic.

from __future__ import print_function
from pyimsl.math.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