1 /* 2 !!DESCRIPTION!! C-Manual Chapter 2.44: floating point constants 3 !!ORIGIN!! LCC 4.1 Testsuite 4 !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC 5 */ 6 7 #include "common.h" 8 9 struct defs { 10 int cbits; /* No. of bits per char */ 11 int ibits; /* int */ 12 int sbits; /* short */ 13 int lbits; /* long */ 14 int ubits; /* unsigned */ 15 int fbits; /* float */ 16 int dbits; /* double */ 17 #ifndef NO_FLOATS 18 float fprec; /* Smallest number that can be */ 19 float dprec; /* significantly added to 1. */ 20 #endif 21 int flgs; /* Print return codes, by section */ 22 int flgm; /* Announce machine dependencies */ 23 int flgd; /* give explicit diagnostics */ 24 int flgl; /* Report local return codes. */ 25 int rrc; /* recent return code */ 26 int crc; /* Cumulative return code */ 27 char rfs[8]; /* Return from section */ 28 }; 29 30 int lbits; /* long */ 31 int ubits; /* unsigned */ 32 int fbits; /* float */ 33 int dbits; /* double */ 34 #ifndef NO_FLOATS 35 float fprec; /* Smallest number that can be */ 36 float dprec; /* significantly added to 1. */ 37 #endif 38 int flgs; /* Print return codes, by section */ 39 int flgm; /* Announce machine dependencies */ 40 int flgd; /* give explicit diagnostics */ 41 int flgl; /* Report local return codes. */ 42 int rrc; /* recent return code */ 43 int crc; /* Cumulative return code */ 44 char rfs[8]; /* Return from section */ 45 46 #ifndef NO_OLD_FUNC_DECL 47 s244(pd0) 48 struct defs *pd0; 49 { 50 #else 51 s244(struct defs *pd0) { 52 #endif 53 54 #ifndef NO_FLOATS 55 double a[8]; 56 57 int rc, lrc, j; 58 static char s244er[] = "s244,er%d\n"; 59 static char qs244[8] = "s244 "; 60 char *ps, *pt; 61 62 ps = qs244; 63 pt = pd0->rfs; 64 while(*pt++ = *ps++); 65 rc = 0; 66 lrc = 0; 67 68 /* Unfortunately, there's not a lot we can do with floating constants. 69 We can check to see that the various representations can be com- 70 piled, that the conversion is such that they yield the same hard- 71 ware representations in all cases, and that all representations 72 thus checked are double precision. */ 73 74 a[0] = .1250E+04; 75 a[1] = 1.250E3; 76 a[2] = 12.50E02; 77 a[3] = 125.0e+1; 78 a[4] = 1250e00; 79 a[5] = 12500.e-01; 80 a[6] = 125000e-2; 81 a[7] = 1250.; 82 83 lrc = 0; 84 for (j=0; j<7; j++) if(a[j] != a[j+1]) lrc = 1; 85 86 if(lrc != 0) { 87 if(pd0->flgd != 0) printf(s244er,1); 88 rc = rc+1; 89 } 90 91 if ( (sizeof .1250E+04 ) != sizeof(double) 92 || (sizeof 1.250E3 ) != sizeof(double) 93 || (sizeof 12.50E02 ) != sizeof(double) 94 || (sizeof 1.250e+1 ) != sizeof(double) 95 || (sizeof 1250e00 ) != sizeof(double) 96 || (sizeof 12500.e-01) != sizeof(double) 97 || (sizeof 125000e-2 ) != sizeof(double) 98 || (sizeof 1250. ) != sizeof(double)){ 99 if(pd0->flgd != 0) printf(s244er,2); 100 rc = rc+2; 101 } 102 103 return rc; 104 105 #else 106 107 return 0; 108 109 #endif 110 } 111 112 /********************************************************************************************* 113 the main loop that launches the sections 114 *********************************************************************************************/ 115 116 #define cq_sections 1 117 118 #ifndef NO_TYPELESS_STRUCT_PTR section(int j,struct * pd0)119 int section(int j,struct* pd0){ 120 #else 121 int section(int j,void* pd0){ 122 #endif 123 switch(j){ 124 case 0: return s244(pd0); 125 } 126 } 127 128 /* 129 C REFERENCE MANUAL (main) 130 */ 131 132 #ifndef NO_OLD_FUNC_DECL 133 main(n,args) 134 int n; 135 char **args; 136 { 137 #else 138 int main(int n,char **args) { 139 #endif 140 141 int j; 142 static struct defs d0, *pd0; 143 144 d0.flgs = 1; /* These flags dictate */ 145 d0.flgm = 1; /* the verbosity of */ 146 d0.flgd = 1; /* the program. */ 147 d0.flgl = 1; 148 149 pd0 = &d0; 150 151 for (j=0; j<cq_sections; j++) { 152 d0.rrc=section(j,pd0); 153 d0.crc=d0.crc+d0.rrc; 154 if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc); 155 } 156 157 if(d0.crc == 0) printf("\nNo errors detected.\n"); 158 else printf("\nFailed.\n"); 159 160 return d0.crc; 161 } 162