source: tests/manipulatorsOutput3.cfa @ be91ab4

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since be91ab4 was 9edf835, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

more work on manipulators for int128 numbers

  • Property mode set to 100644
File size: 3.8 KB
Line 
1#include <fstream.hfa>
2int main() {
3    int128 x = 0xffff, y = 0x2;
4    x <<= 64;
5    x += 0xffff;
6    y <<= 64;
7    y += 0123;
8    y |= 0x8000000000000000;
9    x = -x;
10    sout | x;
11    sout | sign(x);
12    x = -x;
13    sout | sign(x);
14    sout | nl;
15#if 1
16    sout | bin(x);
17    sout | upcase(bin(x));
18    sout | nobase(bin(x));
19    sout | wd( 95, upcase(bin(x)) );
20    sout | wd( 95,90, upcase(bin(x)) );
21    sout | wd( 25,30, upcase(hex(x)) );
22    sout | nl;
23
24    printf( "%#.10o\n", 0123 );
25    sout | wd( 1,10, oct(0123) );
26    sout | oct(x);
27    sout | nobase(oct(x));
28    sout | wd( 45, oct(0123) );
29    sout | wd( 45,40, oct(0123) );
30    sout | wd( 40,45, oct(0123) );
31    sout | wd( 45, oct(x) );
32    sout | wd( 45,40, oct(x) );
33    sout | wd( 40,45, oct(x) );
34
35    sout | left(wd( 45, oct(0123) )) | 'X';
36    sout | left(wd( 45, oct(x) )) | 'X';
37    sout | left(wd( 45, oct(y) )) | 'X';
38    sout | left(wd( 45,40, oct(0123) )) | 'X';
39    sout | left(wd( 45,40, oct(x) )) | 'X';
40    sout | left(wd( 45,40, oct(y) )) | 'X';
41    sout | left(wd( 40,45, oct(0123) )) | 'X';
42    sout | left(wd( 40,45, oct(x) )) | 'X';
43    sout | left(wd( 40,45, oct(y) )) | 'X';
44    printf( "%#-1.10oX\n", 0123 );
45    sout | left(wd( 1,10, oct(0123) )) | 'X';
46    printf( "%#-40.10oX\n", 0123 );
47    sout | left(wd( 40,10, oct(0123) )) | 'X';
48    sout | left(wd( 40,10, oct(x) )) | 'X';
49    sout | left(wd( 40,10, oct(y) )) | 'X';
50    sout | left(wd( 10,40, oct(0123) )) | 'X';
51    sout | left(wd( 10,40, oct(x) )) | 'X';
52    sout | left(wd( 10,40, oct(y) )) | 'X';
53
54    y = 123456789;
55    sout | left(wd( 45, 49, oct(y) )) | 'X';
56    sout | nl;
57
58    sout | hex(x);
59    sout | upcase(hex(x));
60    sout | nobase(hex(x));
61    sout | wd( 45, upcase(hex(x)) );
62    sout | wd( 45,40, upcase(hex(x)) );
63    sout | wd( 45,49, upcase(hex(x)) );
64    sout | left(wd( 45, upcase(hex(x)) )) | 'X';
65    sout | left(wd( 45,40, upcase(hex(x)) )) | 'X';
66    sout | left(wd( 45,49, upcase(hex(x)) )) | 'X';
67
68    sout | nl | nl;
69
70    int128 divisor = 0x4b3b4ca85a86c47a;
71    divisor <<= 16;
72    divisor += 0x98a224000000000;
73
74    // base 10
75    sout | divisor;
76    sout | wd(2, divisor);
77    sout | wd(3, divisor);
78    sout | wd(10, divisor);
79    sout | wd(24, divisor);
80    sout | wd(38, divisor);
81    sout | wd(39, divisor);
82    sout | wd(40, divisor);
83   
84    sout | wd(40, 30, divisor);
85    sout | wd(40, 38, divisor);
86    sout | wd(40, 40, divisor);
87    sout | pad0(wd(40, divisor));
88    sout | pad0(sign(wd(40,divisor)));
89   
90    // base 2
91    sout | upcase(bin(divisor));
92    sout | wd(38, upcase(bin(divisor)));
93    sout | wd(40, upcase(bin(divisor)));
94    sout | wd(40, 38, upcase(bin(divisor)));
95    sout | wd(40, 30, upcase(bin(divisor)));
96    sout | pad0(sign(wd(40, 38, upcase(bin(divisor)))));
97   
98    // oct
99    sout | upcase(oct(divisor));
100    sout | wd(38, upcase(oct(divisor)));
101    sout | wd(40, upcase(oct(divisor)));
102    sout | wd(40, 38, upcase(oct(divisor)));
103    sout | wd(40, 30, upcase(oct(divisor)));
104    sout | pad0(sign(wd(40, 38, upcase(oct(divisor)))));
105   
106    // hex
107    sout | upcase(hex(divisor));
108    sout | wd(38, upcase(hex(divisor)));
109    sout | wd(40, upcase(hex(divisor)));
110    sout | wd(40, 38, upcase(hex(divisor)));
111    sout | wd(40, 30, upcase(hex(divisor)));
112    sout | pad0(sign(wd(40, 38, upcase(hex(divisor)))));
113
114   
115    sout | bin(divisor);
116    sout | upcase(bin(divisor));
117    sout | oct(divisor);
118    sout | hex(divisor);
119    sout | upcase(hex(divisor));
120    sout | nobase(bin(divisor)) | nobase(oct(divisor)) | nobase(hex(divisor));
121    sout | sign(divisor);
122    sout | -divisor;
123    sout | sign(-divisor);
124    sout | wd(2, divisor);
125    sout | wd(3,10,divisor);
126    sout | left(wd(40,divisor)) | 'X';
127    sout | left(sign(wd(40, divisor))) | 'X';
128    sout | left(sign(wd(0,40, divisor))) | 'X';
129    printf( "%-+1.40dX\n", 123456789 );
130#endif // 0
131}
Note: See TracBrowser for help on using the repository browser.