2 !!DESCRIPTION!! C-Manual Chapter 2.6: Hardware Characteristics
3 !!ORIGIN!! LCC 4.1 Testsuite
4 !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
11 int cbits; /* No. of bits per char */
13 int sbits; /* short */
15 int ubits; /* unsigned */
16 int fbits; /* float */
17 int dbits; /* double */
19 float fprec; /* Smallest number that can be */
20 float dprec; /* significantly added to 1. */
22 int flgs; /* Print return codes, by section */
23 int flgm; /* Announce machine dependencies */
24 int flgd; /* give explicit diagnostics */
25 int flgl; /* Report local return codes. */
26 int rrc; /* recent return code */
27 int crc; /* Cumulative return code */
28 char rfs[8]; /* Return from section */
32 int ubits; /* unsigned */
33 int fbits; /* float */
34 int dbits; /* double */
36 float fprec; /* Smallest number that can be */
37 float dprec; /* significantly added to 1. */
39 int flgs; /* Print return codes, by section */
40 int flgm; /* Announce machine dependencies */
41 int flgd; /* give explicit diagnostics */
42 int flgl; /* Report local return codes. */
43 int rrc; /* recent return code */
44 int crc; /* Cumulative return code */
45 char rfs[8]; /* Return from section */
50 section s26, which pokes around at the hardware
51 trying to figure out the characteristics of the machine that
52 it is running on, saves information that is subsequently
53 used by sections s626, s72, and s757. If this program is
54 to be broken up into smallish pieces, say for running on
55 a microcomputer, take care to see that s26 is called before
56 calling any of the latter three sections.
60 2.6 Hardware Characteristics
63 #ifndef NO_OLD_FUNC_DECL
68 s26(struct defs *pd0) {
70 static char qs26[8] = "s26 ";
74 float temp, one, delta;
77 static char s[] = "%3d bits in %ss.\n";
78 static char s2[] = "%e is the least number that can be added to 1. (%s).\n";
85 /* Here, we shake the machinery a little to see what falls
86 out. First, we find out how many bits are in a char. */
94 pd0->cbits = pd0->cbits+1;
96 /* That information lets us determine the size of everything else. */
98 pd0->ibits = pd0->cbits * sizeof(int);
99 pd0->sbits = pd0->cbits * sizeof(short);
100 pd0->lbits = pd0->cbits * sizeof(long);
101 pd0->ubits = pd0->cbits * sizeof(unsigned);
103 pd0->fbits = pd0->cbits * sizeof(float);
104 pd0->dbits = pd0->cbits * sizeof(double);
107 /* We have now almost reconstructed the table in section 2.6, the
108 exception being the range of the floating point hardware.
109 Now there are just so many ways to conjure up a floating point
110 representation system that it's damned near impossible to guess
111 what's going on by writing a program to interpret bit patterns.
112 Further, the information isn't all that useful, if we consider
113 the fact that machines that won't handle numbers between 10**30
114 and 10**-30 are very hard to find, and that people playing with
115 numbers outside that range have a lot more to worry about than
116 just the capacity of the characteristic.
118 A much more useful measure is the precision, which can be ex-
119 pressed in terms of the smallest number that can be added to
120 1. without loss of significance. We calculate that here, for
131 pd0->fprec = delta * 4.;
135 while(tempd != oned) {
139 pd0->dprec = delta * 4.;
142 /* Now, if anyone's interested, we publish the results. */
144 #ifndef CQ26_INCLUDED
146 printf(s,pd0->cbits,"char");
147 printf(s,pd0->ibits,"int");
148 printf(s,pd0->sbits,"short");
149 printf(s,pd0->lbits,"long");
150 printf(s,pd0->ubits,"unsigned");
151 printf(s,pd0->fbits,"float");
152 printf(s,pd0->dbits,"double");
154 printf(s2,pd0->fprec,"float");
155 printf(s2,pd0->dprec,"double");
157 printf("NO_FLOATS\n");
161 /* Since we are only exploring and perhaps reporting, but not
162 testing any features, we cannot return an error code. */
167 #ifndef CQ26_INCLUDED
169 /*********************************************************************************************
170 the main loop that launches the sections
171 *********************************************************************************************/
173 #ifndef NO_TYPELESS_STRUCT_PTR
174 int section(int j,struct* pd0){
176 int section(int j,void* pd0){
179 case 0: return s26(pd0);
183 #define cq_sections 1
186 C REFERENCE MANUAL (main)
189 #ifndef NO_OLD_FUNC_DECL
195 int main(int n,char **args) {
199 static struct defs d0, *pd0;
201 d0.flgs = 1; /* These flags dictate */
202 d0.flgm = 1; /* the verbosity of */
203 d0.flgd = 1; /* the program. */
208 for (j=0; j<cq_sections; j++) {
209 d0.rrc=section(j,pd0);
210 d0.crc=d0.crc+d0.rrc;
211 if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
214 if(d0.crc == 0) printf("\nNo errors detected.\n");
215 else printf("\nFailed.\n");