source: tests/io/manipulatorsOutput3.cfa @ 029cbc0

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 029cbc0 was d86e814, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

add header

  • Property mode set to 100644
File size: 11.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
3//
4// manipulatorsOutput3.cfa --
5//
6// Author           : Peter A. Buhr
7// Created On       : Tue Apr 13 17:54:23 2021
8// Last Modified By : Peter A. Buhr
9// Last Modified On : Tue Apr 13 17:54:48 2021
10// Update Count     : 1
11//
12
13#include <fstream.hfa>
14
15int main() {
16        // int128 printing
17        int128 x = 0xffff, y = 0x2;
18
19        x <<= 64;
20        x += 0xffff;
21        y <<= 64;
22        y += 0123;
23        y |= 0x8000000000000000;
24        x = -x;
25        sout | x;
26        sout | sign(x);
27        x = -x;
28        sout | sign(x);
29        sout | nl;
30
31        int128 divisor = 0x4b3b4ca85a86c47a;
32        divisor <<= 16;
33        divisor += 0x98a224000000000;
34       
35        // base 2
36        sout | "base 2";
37        sout | bin(x);
38        sout | upcase(bin(x));
39        sout | nobase(bin(x));
40        sout | wd( 95, upcase(bin(x)) );
41        sout | wd( 95,90, upcase(bin(x)) );
42        sout | wd( 25,30, upcase(hex(x)) );
43        sout | nl;
44
45        sout | bin(divisor);
46        sout | upcase(bin(divisor));
47        sout | wd(38, upcase(bin(divisor)));
48        sout | wd(40, upcase(bin(divisor)));
49        sout | wd(40, 38, upcase(bin(divisor)));
50        sout | wd(40, 30, upcase(bin(divisor)));
51        sout | pad0(sign(wd(40, 38, upcase(bin(divisor)))));
52        sout | nl;
53       
54        // oct
55        sout | "base 8";
56        printf( "%#.10o\n", 0123 );
57        sout | wd( 1,10, oct(0123) );
58        sout | oct(x);
59        sout | nobase(oct(x));
60        sout | wd( 45, oct(0123) );
61        sout | wd( 45,40, oct(0123) );
62        sout | wd( 40,45, oct(0123) );
63        sout | wd( 45, oct(x) );
64        sout | wd( 45,40, oct(x) );
65        sout | wd( 40,45, oct(x) );
66
67        sout | left(wd( 45, oct(0123) )) | 'X';
68        sout | left(wd( 45, oct(x) )) | 'X';
69        sout | left(wd( 45, oct(y) )) | 'X';
70        sout | left(wd( 45,40, oct(0123) )) | 'X';
71        sout | left(wd( 45,40, oct(x) )) | 'X';
72        sout | left(wd( 45,40, oct(y) )) | 'X';
73        sout | left(wd( 40,45, oct(0123) )) | 'X';
74        sout | left(wd( 40,45, oct(x) )) | 'X';
75        sout | left(wd( 40,45, oct(y) )) | 'X';
76        printf( "%#-1.10oX\n", 0123 );
77        sout | left(wd( 1,10, oct(0123) )) | 'X';
78        printf( "%#-40.10oX\n", 0123 );
79        sout | left(wd( 40,10, oct(0123) )) | 'X';
80        sout | left(wd( 40,10, oct(x) )) | 'X';
81        sout | left(wd( 40,10, oct(y) )) | 'X';
82        sout | left(wd( 10,40, oct(0123) )) | 'X';
83        sout | left(wd( 10,40, oct(x) )) | 'X';
84        sout | left(wd( 10,40, oct(y) )) | 'X';
85
86        y = 01234567;
87        sout | left(wd( 45, 49, oct(y) )) | 'X';
88        y = -y;
89        sout | wd(0, oct(y)) | 'Y';
90        sout | left(wd(0, oct(y))) | 'Y';
91        sout | nl;
92
93        sout | upcase(oct(divisor));
94        sout | wd(38, upcase(oct(divisor)));
95        sout | wd(40, upcase(oct(divisor)));
96        sout | wd(40, 38, upcase(oct(divisor)));
97        sout | wd(40, 30, upcase(oct(divisor)));
98        sout | pad0(sign(wd(40, 38, upcase(oct(divisor)))));
99        sout | nl;
100
101        // decimal
102        sout | "base 10";
103        sout | divisor;
104        sout | wd(2, divisor);
105        sout | wd(3, divisor);
106        sout | wd(10, divisor);
107        sout | wd(24, divisor);
108        sout | wd(38, divisor);
109        sout | wd(39, divisor);
110        sout | wd(40, divisor);
111       
112        sout | wd(40, 30, divisor);
113        sout | wd(40, 38, divisor);
114        sout | wd(40, 40, divisor);
115        sout | pad0(wd(40, divisor));
116        sout | pad0(sign(wd(40,divisor)));
117        sout | nl;
118       
119        // hex
120        sout | "base 16";
121
122        sout | hex(x);
123        sout | upcase(hex(x));
124        sout | nobase(hex(x));
125        sout | wd( 45, upcase(hex(x)) );
126        sout | wd( 45,40, upcase(hex(x)) );
127        sout | wd( 45,49, upcase(hex(x)) );
128        sout | left(wd( 45, upcase(hex(x)) )) | 'X';
129        sout | left(wd( 45,40, upcase(hex(x)) )) | 'X';
130        sout | left(wd( 45,49, upcase(hex(x)) )) | 'X';
131        sout | nl;
132
133        sout | upcase(hex(divisor));
134        sout | wd(38, upcase(hex(divisor)));
135        sout | wd(40, upcase(hex(divisor)));
136        sout | wd(40, 38, upcase(hex(divisor)));
137        sout | wd(40, 30, upcase(hex(divisor)));
138        sout | pad0(sign(wd(40, 38, upcase(hex(divisor)))));
139        sout | nl;
140
141        // extras
142        sout | "extras";
143        sout | bin(divisor);
144        sout | upcase(bin(divisor));
145        sout | oct(divisor);
146        sout | hex(divisor);
147        sout | upcase(hex(divisor));
148        sout | nobase(bin(divisor)) | nobase(oct(divisor)) | nobase(hex(divisor));
149        sout | sign(divisor);
150        sout | -divisor;
151        sout | sign(-divisor);
152        sout | wd(2, divisor);
153        sout | wd(3,10,divisor);
154        sout | left(wd(40,divisor)) | 'X';
155        sout | left(sign(wd(40, divisor))) | 'X';
156        sout | left(sign(wd(0,40, divisor))) | 'X';
157        printf( "%-+1.40dX\n", 123456789 );
158
159        int128 i128;
160        unsigned int128 ui128;
161        i128 = -1000;
162        for ( 10 ) {
163                sout | left( sign( wd( 2, i128 ) ) ) | left( wd( 2, hex( i128 ) ) ) | left( wd( 2, oct( i128 ) ) );
164                sout | left( wd( 2, bin( i128 ) ) );
165                i128 += 1;
166        }
167        sout | nl;
168        sout | nl;
169
170        sout | left( wd( 160, i128 ) );
171        sout | left( sign( wd( 0, i128 ) ) );
172        sout | left( wd( 0, hex( i128 ) ) );
173        sout | left( wd( 0, oct( i128 ) ) );
174        sout | left( wd( 0, bin( i128 ) ) );
175        sout | left( sign( wd( 1, i128 ) ) );
176        sout | left( wd( 1, hex( i128 ) ) );
177        sout | left( wd( 1, oct( i128 ) ) );
178        sout | left( wd( 1, bin( i128 ) ) );
179        sout | left( sign( wd( 32, i128 ) ) );
180        sout | left( wd( 32, hex( i128 ) ) );
181        sout | left( wd( 32, oct( i128 ) ) );
182        sout | left( wd( 32, bin( i128 ) ) );
183        sout | left( sign( wd( 160, i128 ) ) );
184        sout | left( wd( 160, hex( i128 ) ) );
185        sout | left( wd( 160, oct( i128 ) ) );
186        sout | left( wd( 160, bin( i128 ) ) );
187        sout | left( sign( wd( 160, i128 ) ) );
188        sout | left( wd( 160, upcase( hex( i128 ) ) ) );
189        sout | left( wd( 160, upcase( oct( i128 ) ) ) );
190        sout | left( wd( 160, upcase( bin( i128 ) ) ) );
191
192        x = 1234;
193        x <<= 64;
194        x += 5678;
195        sout | x | 'X';
196        sout | wd(45, 20, oct(x)) | 'X';
197        sout | left(wd(45, 20, oct(x))) | 'X';
198        sout | wd(45, 21, oct(x)) | 'X';
199        sout | left(wd(45, 21, oct(x))) | 'X';
200        sout | wd(45, 22, oct(x)) | 'X';
201        sout | left(wd(45, 22, oct(x))) | 'X';
202        sout | wd(45, 36, oct(x)) | 'X';
203        sout | left(wd(45, 36, oct(x))) | 'X';
204        sout | wd(45, 46, oct(x)) | 'X';
205        sout | left(wd(45, 46, oct(x))) | 'X';
206        sout | left(wd(45, 20, oct(x))) | 'X';
207        sout | left(wd(45, 22, oct(x))) | 'X';
208        sout | left(wd(45, 24, oct(x))) | 'X';
209        sout | left(wd(45, 26, oct(x))) | 'X';
210        sout | left(wd(45, 28, oct(x))) | 'X';
211
212        y = -x;
213        sout | oct(y) | 'Y';
214        sout | left(wd(0, oct(y))) | 'Y';
215        sout | left(wd(20, oct(y))) | 'Y';
216        sout | left(wd(26, oct(y))) | 'Y';
217        sout | left(wd(40, oct(y))) | 'Y';
218        sout | left(wd(41, oct(y))) | 'Y';
219        sout | left(wd(45, oct(y))) | 'Y';
220        sout | left(wd(45, 49, oct(y))) | 'Y';
221        sout | left(wd(45, 4, oct(y))) | 'Y';
222        sout | left(wd( 45, oct(0123) )) | 'X';
223        sout | left(wd( 45, oct(x) )) | 'X';
224        sout | left(wd( 45,40, oct(0123) )) | 'X';
225        sout | left(wd( 45,40, oct(x) )) | 'X';
226        sout | left(wd( 40,45, oct(0123) )) | 'X';
227        sout | left(wd( 40,45, oct(x) )) | 'X';
228        sout | left(wd( 40,10, oct(0123) )) | 'X';
229        sout | left(wd( 40,10, oct(x) )) | 'X';
230        sout | left(wd( 40,10, oct(y) )) | 'X';
231        sout | left(wd( 10,40, oct(0123) )) | 'X';
232        sout | left(wd( 10,40, oct(x) )) | 'X';
233        sout | left(wd( 10,40, oct(y) )) | 'X';
234
235        x = 0xffff, y = 0x2;
236        int128 z = 0x_ffff_ffff_ffff_ffff;
237        x <<= 64;
238        x += 0xffff;
239        y <<= 64;
240        y += 0123;
241        y |= 0x8000000000000000;
242
243        for ( int128 i = 0; i < 8; i += 1 ) {
244                sout | nobase(oct(z + 0x8000000000000000 * i));
245        } // for
246
247        sout | bin(x);
248        sout | upcase(bin(x));
249        sout | nobase(bin(x));
250
251        sout | wd( 95, upcase(bin(x)) );
252        sout | wd( 95,90, upcase(bin(x)) );
253        sout | wd( 90,95, upcase(bin(x)) );
254
255        sout | left(bin(x));
256        sout | left(upcase(bin(x)));
257        sout | left(nobase(bin(x)));
258
259        sout | left(wd( 95, upcase(bin(x)) ));
260        sout | left(wd( 95,90, upcase(bin(x)) ));
261        sout | left(wd( 95,81, upcase(bin(x)) ));
262
263        sout | left(wd( 95,80, upcase(bin(x)) ));
264        sout | left(wd( 95,79, upcase(bin(x)) ));
265        sout | left(wd( 95,90, upcase(bin(0xffff)) ));
266
267        sout | left(wd( 68,64, upcase(bin(0xffff)) ));
268        sout | left(wd( 90,95, upcase(bin(x)) ));
269
270        printf( "%#30.25X\n", 0xffff );
271        sout | wd( 30,25, upcase(hex(0xffff)) );
272        printf( "%#25.30X\n", 0xffff );
273        sout | wd( 25,30, upcase(hex(0xffff)) );
274
275        sout | oct(y);
276        sout | wd( 45, oct(y) );
277        sout | left(wd( 45, oct(y) )) | 'X';
278
279        sout | left(wd( 40,10, oct(0123) )) | 'X';
280        sout | left(wd( 40,10, oct(x) )) | 'X';
281        sout | left(wd( 40,10, oct(y) )) | 'X';
282        sout | left(wd( 10,40, oct(0123) )) | 'X';
283        sout | left(wd( 10,40, oct(x) )) | 'X';
284        sout | left(wd( 10,40, oct(y) )) | 'X';
285
286        i128 = -10;
287        for ( 25 ) {
288                sout | left( sign( wd( 20, i128 ) ) ) | left( wd( 20, hex( i128 ) ) ) | left( wd( 20, oct( i128 ) ) );
289                sout | left( wd( 20, bin( i128 ) ) );
290                i128 += 1;
291        } // for
292        sout | nl;
293
294        i128 = 0x7fffffffffffffff;
295        i128 <<= 64;
296        i128 += 0xfffffffffffffffa;
297
298//      for ( 20 ) {
299        volatile int stop = 20;                                                         // gcc compiler bug
300        for ( int i = 0; i < stop; i += 1 ) {
301                sout | i128;
302                sout | left( sign( wd( 45, i128 ) ) ) | left( wd( 45, hex( i128 ) ) ) | left( wd( 45, oct( i128 ) ) );
303                sout | left( wd( 45, bin( i128 ) ) );
304                i128 += 1;
305        } // for
306        sout | nl;
307
308        ui128 = 0x7fffffffffffffff;
309        ui128 <<= 64;
310        ui128 += 0xfffffffffffffffa;
311       
312        for ( 20 ) {
313                sout | ui128;
314                ui128 += 1;
315        }
316        sout | nl;
317
318        ui128 = 0xffffffffffffffff;
319        ui128 <<= 64;
320        ui128 += 0xfffffffffffffffa;
321       
322        for ( 20 ) {
323                sout | ui128;
324                ui128 += 1;
325        }
326
327        // int128 constants (and printing)
328        int128 v = 0xffff_ffffffff_ffffffff_L128 + 0xffffffff_ffffffff_ffffffff_ffffffff_L128;
329        sout | hex(v);
330        v = 0xffff_ffffffff_ffffffff_L128 + 0xffffffff_ffffffff_ffffffff_ffffffff_L128;
331        sout | hex(v);
332        sout | nl;
333
334        sout | "binary";
335        sout | bin(v);
336        sout | bin(0b_11111111111111111111111111111111_L128);
337        sout | bin(0b_11111111111111111111111111111111_11111111111111111111111111111111_L128);
338        sout | bin(0b_11111111111111111111111111111111_11111111111111111111111111111111_11111111111111111111111111111111_L128);
339        sout | bin(0b_11111111111111111111111111111111_11111111111111111111111111111111_11111111111111111111111111111111_11111111111111111111111111111111_L128);
340        sout | hex(0b_10100010001101000101011001111000_L128);
341        sout | hex(0b_10100010001101000101011001111000_10100111011001010100001100100001_L128);
342        sout | hex(0b_10100010001101000101011001111000_10100111011001010100001100100001_11000010001101000101011001111000_L128);
343        sout | hex(0b_10100010001101000101011001111000_10100111011001010100001100100001_11000010001101000101011001111000_11010111010101010100001100100001_L128);
344        sout | nl;
345
346        sout | "octal";
347        sout | oct(v);
348        sout | oct(0_123456_L128u);
349        sout | oct(0_123456_65432_uL128);
350        sout | oct(0_123456_65432_34567_L128);
351        sout | oct(0_123456_65432_34567_76543_L128);
352        sout | oct(0_123456_65432_34567_76543_23456_L128);
353        sout | oct(0_123456_65432_34567_76543_23456_65432_L128);
354        sout | oct(0_123456_65432_34567_76543_23456_65432_34567_L128);
355        sout | oct(0_123456_65432_34567_76543_23456_65432_34567_76543_L128);
356        sout | oct(0_1111111111111111111L);
357        sout | oct(0_11111111111111111111L);
358        sout | oct(0_111111111111111111111L);
359        sout | nl;
360
361        sout | "decimal";
362        sout | v;
363        sout | 42_798_L128 | oct(42_798_L128);
364        sout | 1_402_432_282_L128 | oct(1_402_432_282_L128);
365        sout | 45_954_901_031_287_L128 | oct(45_954_901_031_287_L128);
366        sout | 1_505_850_196_993_244_515_L128 | oct(1_505_850_196_993_244_515_L128);
367        sout | 394_749_758_663_249_135_511_342_L128 | oct(394_749_758_663_249_135_511_342_L128);
368        sout | 12_935_154_696_204_706_112_391_834_394_L128 | oct(12_935_154_696_204_706_112_391_834_394_L128);
369        sout | 423_859_149_128_410_414_395_372_834_994_551_L128 | oct(423_859_149_128_410_414_395_372_834_994_551_L128);
370        sout | 13_889_016_598_639_747_063_234_935_497_057_631_587_L128 | oct(13_889_016_598_639_747_063_234_935_497_057_631_587_L128);
371        sout | 1234567890123456789_uL128;
372        sout | 1234567890123456789_L128u;
373        sout | 0x_7fffffff_ffffffff_ffffffff_ffffffff_L128;
374        sout | 0x_ffffffff_ffffffff_ffffffff_ffffffff_L128;
375        sout | 0x_80000000_00000000_00000000_00000000_L128;
376        unsigned int128 vv;
377        vv = 340282366920938463463374607431768211455_L128u;
378        sout | vv;
379        vv = 170141183460469231731687303715884105727_L128;
380        sout | vv;
381        sout | nl;
382
383        sout | "hexadecimal";
384        sout | hex(v);
385        sout | hex(0x_ffffffff_L128);
386        sout | hex(0x_ffffffff_ffffffff_L128);
387        sout | hex(0x_ffffffff_ffffffff_ffffffff_L128);
388        sout | hex(0xffffffff_ffffffff_ffffffff_ffffffff_L128);
389        sout | hex(0x_a2345678_L128);
390        sout | hex(0x_a2345678_b7654321_L128);
391        sout | hex(0x_a2345678_b7654321_c2345678_L128);
392        sout | hex(0x_a2345678_b7654321_c2345678_d7654321_L128);
393        sout | nl;
394} // main
395
396// Local Variables: //
397// tab-width: 4 //
398// compile-command: "cfa -Wall -Wextra manipulatorsOutput3.cfa" //
399// End: //
Note: See TracBrowser for help on using the repository browser.