File: gcdtest.5c

package info (click to toggle)
nickle 2.77-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,612 kB
  • ctags: 3,746
  • sloc: ansic: 26,986; yacc: 1,873; sh: 954; lex: 884; makefile: 225
file content (53 lines) | stat: -rw-r--r-- 886 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
int function gcd_euclid (int u, int v)
{
    int steps = 0;
    if (u == 0 || v == 0)
	return 0;
    while (v > 0)
    {
	int t = u % v;
	u = v;
	v = t;
	steps++;
    }
    return u;
}

autoimport PRNG;

bool gcd_verify = true;

exception bad_gcd (int u, int v);

void function gcd_check (int u, int v)
{
    int	weber = gcd (u,v);
    if (gcd_verify)
    {
	int euclid = gcd_euclid (u,v);
	if (weber != euclid)
	    raise bad_gcd (u,v);
    }
    else
	for (int i = 0; i < 100; i++)
	    int	weber = gcd (u,v);
}

void function gcd_random (int ubits, int vbits)
{
    int	    u = randbits (ubits);
    int	    v = randbits (vbits);

    gcd_check (u, v);
}

void function gcd_test (int amin, int amax, int bmin, int bmax)
{
    int	a, b;

    for (a = amin; a <= amax; a += randint(10))
	for (b = bmin; b <= bmax; b += randint(10))
	    gcd_random (a, b);
}

gcd_test (2, 200, 2, 200)