summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.cpp104
1 files changed, 103 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index d436a20..6674075 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,5 +1,7 @@
1#include "number.h" 1#include "number.h"
2#include "packedintarray.h" 2#include "packedintarray.h"
3#include <math.h>
4#include <sys/time.h>
3 5
4#include <bu/sio.h> 6#include <bu/sio.h>
5using namespace Bu; 7using namespace Bu;
@@ -177,6 +179,18 @@ void numbertest1()
177 arg( a.toString() ). 179 arg( a.toString() ).
178 arg( b.toString() ). 180 arg( b.toString() ).
179 arg( (a % b).toString() ); 181 arg( (a % b).toString() );
182
183 a = "983429807324875233421784598754987439873472349875329853298732";
184 b = "18446744073709551615";
185
186 println("%1 / %2 = %3").
187 arg( a.toString() ).
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() );
180} 194}
181 195
182#define compcheck( anum, op, bnum ) \ 196#define compcheck( anum, op, bnum ) \
@@ -245,13 +259,101 @@ void numbertestcomp()
245 compcheck( 123, <=, -122 ); 259 compcheck( 123, <=, -122 );
246} 260}
247 261
262int getHob( int x )
263{
264 for( int j = 31; j >= 0; j-- )
265 {
266 if( x&(1<<j) )
267 {
268 return j+1;
269 }
270 }
271 return 0;
272}
273
274int getOrd( int x )
275{
276 return (int)(log(x)*0xb.8aa3b295c17fp-3+1.0);
277}
278
279double getTime()
280{
281 timeval t;
282 gettimeofday( &t, NULL );
283 return (double)t.tv_sec + (double)(t.tv_usec*.000001);
284}
285
286void ordertest()
287{
288 for( int j = 2; j < 64; j++ )
289 {
290 if( getOrd( j ) != getHob(j-1) )
291 println("Failure on radix %1").arg( j );
292 }
293
294 double dStart, dEnd;
295
296 dStart = getTime();
297 for( int k = 0; k < 100000; k++ )
298 {
299 for( int j = 2; j < 32; j++ )
300 {
301 getOrd( j );
302 }
303 }
304 dEnd = getTime();
305
306 println("getOrd: %1 in %2 (%3 cps)").arg( 30*100000 ).arg( dEnd-dStart ).
307 arg( (30*100000)/(dEnd-dStart) );
308
309 dStart = getTime();
310 for( int k = 0; k < 100000; k++ )
311 {
312 for( int j = 2; j < 32; j++ )
313 {
314 getHob( j-1 );
315 }
316 }
317 dEnd = getTime();
318
319 println("getHob: %1 in %2 (%3 cps)").arg( 30*100000 ).arg( dEnd-dStart ).
320 arg( (30*100000)/(dEnd-dStart) );
321}
322
323void radixtest()
324{
325 Number a( 16 ), b( 16 );
326
327 a = "f8a72bce3";
328 b = "9ea8cb3";
329 println("%1 + %2 = %3").
330 arg( a.toString() ).
331 arg( b.toString() ).
332 arg( (a + b).toString() );
333 println("%1 - %2 = %3").
334 arg( a.toString() ).
335 arg( b.toString() ).
336 arg( (a - b).toString() );
337 println("%1 / %2 = %3").
338 arg( a.toString() ).
339 arg( b.toString() ).
340 arg( (a / b).toString() );
341 println("%1 * %2 = %3").
342 arg( a.toString() ).
343 arg( b.toString() ).
344 arg( (a * b).toString() );
345}
346
248int main( int , char *[] ) 347int main( int , char *[] )
249{ 348{
250 println("CliC"); 349 println("CliC");
251 350
252// packedtest1(); 351// packedtest1();
253 numbertest1(); 352// numbertest1();
254// numbertestcomp(); 353// numbertestcomp();
354 radixtest();
355
356// ordertest();
255 357
256 return 0; 358 return 0;
257} 359}