source: tests/manipulatorsOutput3.cfa @ 1bb1ceb

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 1bb1ceb was 1b5c3d60, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

change uin128 to int128 to make example consistent

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