CNL Stat : Utilities : machine (integer)
machine (integer)
Returns integer information describing the computer’s arithmetic.
Synopsis
#include <imsls.h>
long imsls_i_machine (int 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 imsls_i_machine returns information describing the computer’s arithmetic. This can be used to make programs machine independent.
imsls_i_machine(0) = Number of bits per byte
Assume that integers are represented in M-digit, base-A form as
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
the largest short int
4
M1 the number of base-A digits in a long int
5
the largest long int
Assume that floating-point numbers are represented in N-digit, base B form as
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
the smallest float exponent
9
the largest float exponent
10
Nd, the number of base-B digits in double
11
the largest long int
12
the number of base-B digits in double
Example
In this example, all the values returned by imsls_i_machine on a 32bit machine with IEEE (Institute for Electrical and Electronics Engineer) arithmetic are printed.
 
#include <imsls.h>
#include <stdio.h>
 
int main() {
int n;
long ans;
 
for (n = 0; n <= 12; n++) {
ans = imsls_i_machine(n);
printf("imsls_i_machine(%d) = %ld\n", n, ans);
}
}
Output
 
imsls_i_machine(0) = 8
imsls_i_machine(1) = 2
imsls_i_machine(2) = 15
imsls_i_machine(3) = 32767
imsls_i_machine(4) = 31
imsls_i_machine(5) = 2147483647
imsls_i_machine(6) = 2
imsls_i_machine(7) = 24
imsls_i_machine(8) = -125
imsls_i_machine(9) = 128
imsls_i_machine(10) = 53
imsls_i_machine(11) = -1021
imsls_i_machine(12) = 1024