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