]> www.ginac.de Git - cln.git/blob - tests/test_I_logcount.cc
* configure.ac: Disable shared lib on MinGW.
[cln.git] / tests / test_I_logcount.cc
1 #include "test_I.h"
2
3 int test_I_logcount (int iterations)
4 {
5         int error = 0;
6         int i;
7         // Check additivity.
8         for (i = iterations; i > 0; i--) {
9                 cl_I a = testrandom_I();
10                 cl_I b = testrandom_I();
11                 if (a >= 0 && b >= 0)
12                         ASSERT2(logcount(a) == logcount(logand(a,b)) + logcount(logandc2(a,b)), a,b);
13         }
14         // Check behaviour on sign change.
15         for (i = iterations; i > 0; i--) {
16                 cl_I a = testrandom_I();
17                 ASSERT1(logcount(lognot(a)) == logcount(a), a);
18         }
19         // Check shift invariance.
20         for (i = iterations; i > 0; i--) {
21                 cl_I a = testrandom_I();
22                 sintL b = random32() % 1024;
23                 ASSERT2(logcount(ash(a,b)) == logcount(a) + (minusp(a) ? b : 0), a,b);
24         }
25         return error;
26 }