File: test_I_power2p.cc

package info (click to toggle)
cln 1.1.13-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 13,040 kB
  • ctags: 17,214
  • sloc: cpp: 79,175; sh: 7,794; ansic: 4,194; makefile: 631; lisp: 115
file content (20 lines) | stat: -rw-r--r-- 427 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "test_I.h"

int test_I_power2p (int iterations)
{
	int error = 0;
	int i;
	// Check powers of 2.
	for (i = iterations; i > 0; i--) {
		uintL n = random32() % 1024;
		cl_I a = ash(1,n);
		ASSERT1(power2p(a) == n+1, n);
	}
	// Check against logcount.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		if (a > 0)
			ASSERT1(power2p(a) == (logcount(a) == 1 ? integer_length(a) : 0), a);
	}
	return error;
}