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