Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / ctest / ctconv / conv.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  *
5  */
6
7 /* Author: E.G. Keizer */
8
9 char rcs_id[] = "$Id: conv.c,v 2.5 1994/06/24 12:07:28 ceriel Exp $" ;
10
11 main() {
12         t1() ;
13         t2() ;
14         return 0 ;
15 }
16
17 t1() {
18         char c ; int i ; long l ; unsigned u ;
19 #ifndef NOFLOAT
20         float f ;
21 #endif
22
23         /* test conversions */
24
25         /* first some conversions on constants */
26
27         printf("(int) '\\377' = %d\n",(int) '\377') ;
28         printf("(long) -1 = %ld\n",(long) -1 ) ;
29 #ifndef NOFLOAT
30         printf("(float) 12 = %f\n",(float) 12 ) ;
31         printf("(int) 3.14 = %d\n",(int) 3.14 ) ;
32 #endif
33         printf("(int) 32767L = %d\n",(int) 32767L ) ;
34         printf("(int) -32768L = %d\n",(int) -32768L ) ;
35         printf("(char) 128L = %d\n",(char) 128L) ;
36         printf("(char) 0377 = %d\n",(char) 0377 ) ;
37         printf("(char) -1 = %d\n",(char) -1 ) ;
38         printf("(char) 10000 = %d\n",(char) 10000 ) ;
39
40         /* conversions from characters */
41         printf("From character\n") ;
42         c = 127 ;
43         i=c ;
44         l=c ;
45         u=c ;
46 #ifndef NOFLOAT
47         f=c ;
48 #endif
49         printf("\tchar %5d, int %6d, unsigned %6o, long %11ld\n",c,i,u,l) ;
50 #ifndef NOFLOAT
51         printf("\t\t\t\t\tfloat %f\n",f) ;
52 #endif
53         c = -1 ;
54         i=c ;
55         l=c ;
56         u=c ;
57 #ifndef NOFLOAT
58         f=c ;
59 #endif
60         printf("\tchar %5d, int %6d, unsigned %6o, long %11ld\n",c,i,u,l) ;
61 #ifndef NOFLOAT
62         printf("\t\t\t\t\tfloat %f\n",f) ;
63 #endif
64         c = 0377 ;
65         i=c ;
66         l=c ;
67         u=c ;
68 #ifndef NOFLOAT
69         f=c ;
70 #endif
71         printf("\tchar %5d, int %6d, unsigned %6o, long %11ld\n",c,i,u,l) ;
72 #ifndef NOFLOAT
73         printf("\t\t\t\t\tfloat %f\n",f) ;
74 #endif
75
76         /* from integer */
77         printf("From integer\n") ;
78         i= -64 ;
79         c=i ;
80         l=i ;
81         u=i ;
82 #ifndef NOFLOAT
83         f=i ;
84 #endif
85         printf("\tchar %5d, int %6d, unsigned %6o, long %11ld\n",c,i,u,l) ;
86 #ifndef NOFLOAT
87         printf("\t\t\t\t\tfloat %f\n",f) ;
88 #endif
89         /* from long */
90         printf("From long\n") ;
91         l = -3 ;
92         c = l ;
93         i = l ;
94         u = l ;
95 #ifndef NOFLOAT
96         f = l ;
97 #endif
98         printf("\tchar %5d, int %6d, unsigned %6o, long %11ld\n",c,i,u,l) ;
99 #ifndef NOFLOAT
100         printf("\t\t\t\t\tfloat %f\n",f) ;
101 #endif
102
103         printf("Casts from long\n");
104         l = 75000;
105         printf("\tchar %5d, int %d, unsigned short %6o, long %11ld\n",
106                 (char) l,(int) l,(unsigned short)l ,l) ;
107
108 #ifndef NOFLOAT
109         printf("From float\n") ;
110         f = 121.5 ;
111         c = f ;
112         i = f ;
113         u = f ;
114         l = f ;
115         printf("\tchar %5d, int %6d, unsigned %6o, long %11ld, float %f\n",c,i,u,l,f) ;
116         f = 1e-4 ;
117         c = f ;
118         i = f ;
119         u = f ;
120         l = f ;
121         printf("\tchar %5d, int %6d, unsigned %6o, long %11ld, float %f\n",c,i,u,l,f) ;
122         f = 3276.6e1 ;
123         i = f ;
124         u = f ;
125         l = f ;
126         printf("\tint %6d, unsigned %6o, long %11ld, float %f\n",i,u,l,f) ;
127         f = 1223432e3 ;
128         l = f ;
129         printf("\tlong %11ld, float %f\n",l,f) ;
130 #endif
131
132         /* some special cases */
133         {
134                 int a[4] ;
135
136                 l = 3 ; a[3]= -17 ;
137                 printf("a[l] (l==%ld) %d\n",l,a[l]) ;
138                 printf("a[3l] %d\n",a[3l] ) ;
139
140         }
141         return 0 ;
142 }
143
144 t2()
145 {
146         long l1 = 0x1f010L;
147         long l2;
148
149         l2 = (unsigned short) l1;
150         printf("(unsigned short) 0x1f010L = 0x%lx\n", l2);
151         l2 = (short) l1;
152         printf("(short) 0x1f010L = 0x%lx\n", l2);
153 }