diff options
author | Mike Buland <mike@xagasoft.com> | 2013-04-16 14:53:02 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2013-04-16 14:53:02 -0600 |
commit | eda2bffe27415d28813badc5db572d1e4b20c3de (patch) | |
tree | 481aabb31e47588bb587ae8ec320f80fcede8cdf /src | |
parent | 7cfca326d8f824d3749ece6ad63a793197bf6c9d (diff) | |
download | clic-eda2bffe27415d28813badc5db572d1e4b20c3de.tar.gz clic-eda2bffe27415d28813badc5db572d1e4b20c3de.tar.bz2 clic-eda2bffe27415d28813badc5db572d1e4b20c3de.tar.xz clic-eda2bffe27415d28813badc5db572d1e4b20c3de.zip |
Added formatter for Number.
I'm a little embarassed that I didn't do this from the start, made the
code so much easier to read.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 130 | ||||
-rw-r--r-- | src/number.cpp | 5 | ||||
-rw-r--r-- | src/number.h | 2 |
3 files changed, 38 insertions, 99 deletions
diff --git a/src/main.cpp b/src/main.cpp index 6674075..4454c08 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -38,164 +38,101 @@ void numbertest1() | |||
38 | Number a("1000902491523000321"); | 38 | Number a("1000902491523000321"); |
39 | Number b("3004392012498000700"); | 39 | Number b("3004392012498000700"); |
40 | 40 | ||
41 | println("%1 + %2 = %3"). | 41 | println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); |
42 | arg( a.toString() ). | ||
43 | arg( b.toString() ). | ||
44 | arg( (a + b).toString() ); | ||
45 | 42 | ||
46 | println("%1 * %2 = %3"). | 43 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
47 | arg( a.toString() ). | ||
48 | arg( b.toString() ). | ||
49 | arg( (a * b).toString() ); | ||
50 | 44 | ||
51 | a = "-872"; | 45 | a = "-872"; |
52 | b = "123"; | 46 | b = "123"; |
53 | 47 | ||
54 | println("%1 + %2 = %3"). | 48 | println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); |
55 | arg( a.toString() ). | ||
56 | arg( b.toString() ). | ||
57 | arg( (a + b).toString() ); | ||
58 | 49 | ||
59 | a = "728"; | 50 | a = "728"; |
60 | b = "-51"; | 51 | b = "-51"; |
61 | 52 | ||
62 | println("%1 + %2 = %3"). | 53 | println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); |
63 | arg( a.toString() ). | ||
64 | arg( b.toString() ). | ||
65 | arg( (a + b).toString() ); | ||
66 | 54 | ||
67 | a = "44"; | 55 | a = "44"; |
68 | b = "-55"; | 56 | b = "-55"; |
69 | 57 | ||
70 | println("%1 + %2 = %3"). | 58 | println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); |
71 | arg( a.toString() ). | ||
72 | arg( b.toString() ). | ||
73 | arg( (a + b).toString() ); | ||
74 | 59 | ||
75 | a = "44"; | 60 | a = "44"; |
76 | b = "-66"; | 61 | b = "-66"; |
77 | 62 | ||
78 | println("%1 + %2 = %3"). | 63 | println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); |
79 | arg( a.toString() ). | ||
80 | arg( b.toString() ). | ||
81 | arg( (a + b).toString() ); | ||
82 | 64 | ||
83 | a = "44"; | 65 | a = "44"; |
84 | b = "-66"; | 66 | b = "-66"; |
85 | 67 | ||
86 | println("%1 - %2 = %3"). | 68 | println("%1 - %2 = %3").arg( a ).arg( b ).arg( a - b ); |
87 | arg( a.toString() ). | ||
88 | arg( b.toString() ). | ||
89 | arg( (a - b).toString() ); | ||
90 | 69 | ||
91 | a = "44"; | 70 | a = "44"; |
92 | b = "66"; | 71 | b = "66"; |
93 | 72 | ||
94 | println("%1 - %2 = %3"). | 73 | println("%1 - %2 = %3").arg( a ).arg( b ).arg( a - b ); |
95 | arg( a.toString() ). | ||
96 | arg( b.toString() ). | ||
97 | arg( (a - b).toString() ); | ||
98 | 74 | ||
99 | a = "7814"; | 75 | a = "7814"; |
100 | b = "24"; | 76 | b = "24"; |
101 | 77 | ||
102 | println("%1 * %2 = %3"). | 78 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
103 | arg( a.toString() ). | ||
104 | arg( b.toString() ). | ||
105 | arg( (a * b).toString() ); | ||
106 | 79 | ||
107 | a = "12345"; | 80 | a = "12345"; |
108 | b = "678"; | 81 | b = "678"; |
109 | 82 | ||
110 | println("%1 * %2 = %3"). | 83 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
111 | arg( a.toString() ). | ||
112 | arg( b.toString() ). | ||
113 | arg( (a * b).toString() ); | ||
114 | 84 | ||
115 | a = "3592846"; | 85 | a = "3592846"; |
116 | b = "944634757"; | 86 | b = "944634757"; |
117 | 87 | ||
118 | println("%1 * %2 = %3"). | 88 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
119 | arg( a.toString() ). | ||
120 | arg( b.toString() ). | ||
121 | arg( (a * b).toString() ); | ||
122 | 89 | ||
123 | a = "3592846"; | 90 | a = "3592846"; |
124 | b = ""; | 91 | b = ""; |
125 | 92 | ||
126 | println("%1 * %2 = %3"). | 93 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
127 | arg( a.toString() ). | ||
128 | arg( b.toString() ). | ||
129 | arg( (a * b).toString() ); | ||
130 | 94 | ||
131 | a = "123"; | 95 | a = "123"; |
132 | b = "-45"; | 96 | b = "-45"; |
133 | 97 | ||
134 | println("%1 * %2 = %3"). | 98 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
135 | arg( a.toString() ). | ||
136 | arg( b.toString() ). | ||
137 | arg( (a * b).toString() ); | ||
138 | 99 | ||
139 | a = "-123"; | 100 | a = "-123"; |
140 | b = "45"; | 101 | b = "45"; |
141 | 102 | ||
142 | println("%1 * %2 = %3"). | 103 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
143 | arg( a.toString() ). | ||
144 | arg( b.toString() ). | ||
145 | arg( (a * b).toString() ); | ||
146 | 104 | ||
147 | a = "-123"; | 105 | a = "-123"; |
148 | b = "-45"; | 106 | b = "-45"; |
149 | 107 | ||
150 | println("%1 * %2 = %3"). | 108 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); |
151 | arg( a.toString() ). | ||
152 | arg( b.toString() ). | ||
153 | arg( (a * b).toString() ); | ||
154 | 109 | ||
155 | a = "123"; | 110 | a = "123"; |
156 | b = "45"; | 111 | b = "45"; |
157 | 112 | ||
158 | println("%1 / %2 = %3"). | 113 | println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); |
159 | arg( a.toString() ). | ||
160 | arg( b.toString() ). | ||
161 | arg( (a / b).toString() ); | ||
162 | 114 | ||
163 | a = "12345"; | 115 | a = "12345"; |
164 | b = "45"; | 116 | b = "45"; |
165 | 117 | ||
166 | println("%1 / %2 = %3"). | 118 | println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); |
167 | arg( a.toString() ). | ||
168 | arg( b.toString() ). | ||
169 | arg( (a / b).toString() ); | ||
170 | 119 | ||
171 | a = "3007103450821050020096034077958224700"; | 120 | a = "3007103450821050020096034077958224700"; |
172 | b = "898239467"; | 121 | b = "898239467"; |
173 | 122 | ||
174 | println("%1 / %2 = %3"). | 123 | println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); |
175 | arg( a.toString() ). | 124 | println("%1 %% %2 = %3").arg( a ).arg( b ).arg( a % b ); |
176 | arg( b.toString() ). | ||
177 | arg( (a / b).toString() ); | ||
178 | println("%1 %% %2 = %3"). | ||
179 | arg( a.toString() ). | ||
180 | arg( b.toString() ). | ||
181 | arg( (a % b).toString() ); | ||
182 | 125 | ||
183 | a = "983429807324875233421784598754987439873472349875329853298732"; | 126 | a = "983429807324875233421784598754987439873472349875329853298732"; |
184 | b = "18446744073709551615"; | 127 | b = "18446744073709551615"; |
185 | 128 | ||
186 | println("%1 / %2 = %3"). | 129 | println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); |
187 | arg( a.toString() ). | 130 | println("%1 %% %2 = %3").arg( a ).arg( b ).arg( a % b ); |
188 | arg( b.toString() ). | ||
189 | arg( (a / b).toString() ); | ||
190 | println("%1 %% %2 = %3"). | ||
191 | arg( a.toString() ). | ||
192 | arg( b.toString() ). | ||
193 | arg( (a % b).toString() ); | ||
194 | } | 131 | } |
195 | 132 | ||
196 | #define compcheck( anum, op, bnum ) \ | 133 | #define compcheck( anum, op, bnum ) \ |
197 | a = #anum; b = #bnum; \ | 134 | a = #anum; b = #bnum; \ |
198 | println("%4: %1 " #op " %2 = %3").arg( a.toString() ).arg( b.toString() ). \ | 135 | println("%4: %1 " #op " %2 = %3").arg( a ).arg( b ). \ |
199 | arg( a op b ).arg( ((a op b) == (anum op bnum)) ? "pass" : "fail" ) | 136 | arg( a op b ).arg( ((a op b) == (anum op bnum)) ? "pass" : "fail" ) |
200 | 137 | ||
201 | void numbertestcomp() | 138 | void numbertestcomp() |
@@ -327,21 +264,16 @@ void radixtest() | |||
327 | a = "f8a72bce3"; | 264 | a = "f8a72bce3"; |
328 | b = "9ea8cb3"; | 265 | b = "9ea8cb3"; |
329 | println("%1 + %2 = %3"). | 266 | println("%1 + %2 = %3"). |
330 | arg( a.toString() ). | 267 | arg( a ). |
331 | arg( b.toString() ). | 268 | arg( b ). |
332 | arg( (a + b).toString() ); | 269 | arg( (a + b) ); |
333 | println("%1 - %2 = %3"). | 270 | println("%1 - %2 = %3"). |
334 | arg( a.toString() ). | 271 | arg( a ). |
335 | arg( b.toString() ). | 272 | arg( b ). |
336 | arg( (a - b).toString() ); | 273 | arg( (a - b) ); |
337 | println("%1 / %2 = %3"). | 274 | println("%1 / %2 = %3").arg( a ).arg( b ). |
338 | arg( a.toString() ). | 275 | arg( (a / b) ); |
339 | arg( b.toString() ). | 276 | println("%1 * %2 = %3").arg( a ).arg( b ).arg( (a * b) ); |
340 | arg( (a / b).toString() ); | ||
341 | println("%1 * %2 = %3"). | ||
342 | arg( a.toString() ). | ||
343 | arg( b.toString() ). | ||
344 | arg( (a * b).toString() ); | ||
345 | } | 277 | } |
346 | 278 | ||
347 | int main( int , char *[] ) | 279 | int main( int , char *[] ) |
diff --git a/src/number.cpp b/src/number.cpp index 12a86e0..b045e7c 100644 --- a/src/number.cpp +++ b/src/number.cpp | |||
@@ -431,3 +431,8 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const | |||
431 | // Bu::println("Complete: q = %1, r = %2").arg( q.toString() ).arg( r.toString() ); | 431 | // Bu::println("Complete: q = %1, r = %2").arg( q.toString() ).arg( r.toString() ); |
432 | } | 432 | } |
433 | 433 | ||
434 | Bu::Formatter &operator<<( Bu::Formatter &f, const Number &n ) | ||
435 | { | ||
436 | return f << n.toString(); | ||
437 | } | ||
438 | |||
diff --git a/src/number.h b/src/number.h index 8d98a1b..cdae1df 100644 --- a/src/number.h +++ b/src/number.h | |||
@@ -52,4 +52,6 @@ private: | |||
52 | PackedIntArray aInt; | 52 | PackedIntArray aInt; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | Bu::Formatter &operator<<( Bu::Formatter &f, const Number &n ); | ||
56 | |||
55 | #endif | 57 | #endif |