Commit fa1f1f0c authored by Matthias Braun's avatar Matthias Braun
Browse files

reformatted/improved some testapps

parent 380be6db
......@@ -12,58 +12,58 @@
typedef struct Node Node;
typedef struct Data {
const char *name;
const char *addr;
int account1;
int account2;
int account3;
Node *found;
const char *name;
const char *addr;
int account1;
int account2;
int account3;
Node *found;
} Data;
struct Node {
Data mydata;
int mykey;
Node *son1;
Node *son2;
Node *son3;
Node *son4;
Data mydata;
int mykey;
Node *son1;
Node *son2;
Node *son3;
Node *son4;
};
static int Node_count;
static Node *new_node(int depth) {
Node *res;
res = (void *)malloc(sizeof(*res));
res->mykey = Node_count++; /* @@@ Want Random number */
if (depth > 1) {
res->son1 = new_node(depth-1);
res->son2 = new_node(depth-1);
/*res->son3 = new_node(depth-1);
res->son4 = new_node(depth-1);*/
} else {
res->son1 = NULL;
res->son2 = NULL;
res->son3 = NULL;
res->son4 = NULL;
}
return res;
Node *res;
res = (void *)malloc(sizeof(*res));
res->mykey = Node_count++; /* @@@ Want Random number */
if (depth > 1) {
res->son1 = new_node(depth-1);
res->son2 = new_node(depth-1);
res->son3 = new_node(depth-1);
res->son4 = new_node(depth-1);
} else {
res->son1 = NULL;
res->son2 = NULL;
res->son3 = NULL;
res->son4 = NULL;
}
return res;
}
static int find_max(Node *n) {
if (n->son1 == NULL) {
return n->mykey;
} else {
int max = find_max(n->son1);
int max2 = find_max(n->son2);
if (max2 > max) max = max2;
/*max2 = find_max(n->son3);
if (max2 > max) max = max2;
max2 = find_max(n->son4);
if (max2 > max) max = max2;*/
return max;
}
if (n->son1 == NULL) {
return n->mykey;
} else {
int max = find_max(n->son1);
int max2 = find_max(n->son2);
if (max2 > max) max = max2;
/*max2 = find_max(n->son3);
if (max2 > max) max = max2;
max2 = find_max(n->son4);
if (max2 > max) max = max2;*/
return max;
}
}
......@@ -71,26 +71,26 @@ static int find_max(Node *n) {
static Node *root; /* root of the tree to search */
static void alloc (int depth) {
root = new_node(depth);
root = new_node(depth);
}
static void search (void) {
printf(" Max = %d\n", find_max(root));
printf(" Max = %d\n", find_max(root));
}
int main(int argc, char *argv[]) {
int depth;
printf("Do.c:\n");
if (argc <= 1) {
printf("Usage: Do n\nGive search tree depth!\n");
printf("10 is a good value, 12 too much.\n");
printf("Continuing with default value 9.\n");
depth = 9;
} else {
depth = atoi(argv[1]);
}
alloc(depth);
search();
return 0;
int depth;
printf("Do.c:\n");
if (argc <= 1) {
printf("Usage: Do n\nGive search tree depth!\n");
printf("10 is a good value, 12 too much.\n");
printf("Continuing with default value 9.\n");
depth = 9;
} else {
depth = atoi(argv[1]);
}
alloc(depth);
search();
return 0;
}
......@@ -4,68 +4,68 @@
unsigned int
f1 (int diff)
{
return ((unsigned int) (diff < 0 ? -diff : diff));
return ((unsigned int) (diff < 0 ? -diff : diff));
}
unsigned int
f2 (unsigned int diff)
{
return ((unsigned int) ((signed int) diff < 0 ? -diff : diff));
return ((unsigned int) ((signed int) diff < 0 ? -diff : diff));
}
unsigned long long
f3 (long long diff)
{
return ((unsigned long long) (diff < 0 ? -diff : diff));
return ((unsigned long long) (diff < 0 ? -diff : diff));
}
unsigned long long
f4 (unsigned long long diff)
{
return ((unsigned long long) ((signed long long) diff < 0 ? -diff : diff));
return ((unsigned long long) ((signed long long) diff < 0 ? -diff : diff));
}
int main ()
{
int i;
for (i = 0; i <= 10; i++)
{
/*
if (f1 (i) != i) {
printf("f1(%d)\n", i);
abort ();
}
if (f1 (-i) != i) {
printf("f1(%d)\n", -i);
abort ();
}
if (f2 (i) != i) {
printf("f2(%d)\n", i);
abort ();
}
*/
if ((int) f2 (-i) != i) {
printf("f2(%d) -> %d\n", -i, f2(-i));
abort ();
}
/*
if (f3 ((long long) i) != i) {
printf("f3(%lld)\n", i);
abort ();
}
if (f3 ((long long) -i) != i) {
printf("f3(%lld)\n", -i);
abort ();
}
if (f4 ((long long) i) != i) {
printf("f4(%lld)\n", i);
abort ();
}
if (f4 ((long long) -i) != i) {
printf("f4(%d)\n", -i);
abort ();
}
*/
}
exit (0);
int i;
for (i = 0; i <= 10; i++)
{
#if 0
if (f1 (i) != i) {
printf("f1(%d)\n", i);
abort ();
}
if (f1 (-i) != i) {
printf("f1(%d)\n", -i);
abort ();
}
if (f2 (i) != i) {
printf("f2(%d)\n", i);
abort ();
}
#endif
if ((int) f2 (-i) != i) {
printf("f2(%d) -> %d\n", -i, f2(-i));
abort ();
}
#if 0
if (f3 ((long long) i) != i) {
printf("f3(%lld)\n", i);
abort ();
}
if (f3 ((long long) -i) != i) {
printf("f3(%lld)\n", -i);
abort ();
}
if (f4 ((long long) i) != i) {
printf("f4(%lld)\n", i);
abort ();
}
if (f4 ((long long) -i) != i) {
printf("f4(%d)\n", -i);
abort ();
}
#endif
}
exit (0);
}
......@@ -19,7 +19,7 @@ struct bf {
int main(int argc, char **argv) {
struct bf mybf = { 0xffffffff, 4097, 65537, 5, 0xff, 4.5, 257 };
//dumpMem(&mybf, sizeof mybf);
dumpMem(&mybf, sizeof mybf);
printf("sizeof mybf %d\n", sizeof mybf);
printf("offset a = %d\n", offsetof(struct bf, a));
printf("offset c = %d\n", offsetof(struct bf, c));
......
......@@ -2,42 +2,49 @@ int m = 754974721, N, t[1 << 22], a, *p, i, e = 1 << 22, j, s, b, c, U;
f (d)
{
for (s = 1 << 23; s; s /= 2, d = d * 1L * d % m)
if (s < N)
for (p = t; p < t + N; p += s)
for (i = s, c = 1; i; i--)
b = *p + p[s], p[s] = (m + *p - p[s]) *
1L * c % m, *p++ = b % m, c = c * 1L * d % m;
for (j = 0; i < N - 1;)
{
for (s = N / 2; !((j ^= s) & s); s /= 2);
if (++i < j)
a = t[i], t[i] = t[j], t[j] = a;
}
for (s = 1 << 23; s; s /= 2, d = d * 1L * d % m)
if (s < N)
for (p = t; p < t + N; p += s)
for (i = s, c = 1; i; i--)
b = *p + p[s], p[s] = (m + *p - p[s]) *
1L * c % m, *p++ = b % m, c = c * 1L * d % m;
for (j = 0; i < N - 1;)
{
for (s = N / 2; !((j ^= s) & s); s /= 2)
;
if (++i < j)
a = t[i], t[i] = t[j], t[j] = a;
}
}
int main ()
{
*t = 2;
U = N = 1;
while (e /= 2)
{
N *= 2;
U = U * 1L * (m + 1) / 2 % m;
f (362);
for (p = t; p < t + N;)
*p++ = (*p * 1L ** p % m) * U % m;
f (415027540);
for (a = 0, p = t; p < t + N;)
a += (6972593 & e ? 2 : 1) ** p, *p++ = a % 10, a /= 10;
}
while (!*--p);
t[0]--;
*t = 2;
U = N = 1;
while (e /= 2) {
N *= 2;
U = U * 1L * (m + 1) / 2 % m;
f (362);
for (p = t; p < t + N;)
*p++ = (*p * 1L ** p % m) * U % m;
f (415027540);
for (a = 0, p = t; p < t + N;)
a += (6972593 & e ? 2 : 1) ** p, *p++ = a % 10, a /= 10;
}
while (!*--p)
;
t[0]--;
{
int qs = 0;
while (p >= t)
qs += *p--;
printf ("Checksumme = %d\n", qs);
while (p >= t)
qs += *p--;
printf ("Checksumme = %d\n", qs);
}
return 0;
}
......@@ -48,11 +48,22 @@ int main ()
{
int i;
for (i = 0; i < 32; i++)
for (i = 0; i < 32; i++) {
gd[i] = i, gf[i] = i;
foo (1);
for (i = 0; i < 32; i++)
if (gd[i] != i * 4 || gf[i] != i)
abort ();
}
//foo (1);
for (i = 0; i < 32; i++) {
if (gd[i] != i * 4) {
printf("abort1 (%d) expected %d, got %f\n", i, i*4, gd[i]);
abort ();
}
if(gf[i] != i) {
printf("abort2 (%d)\n", i);
abort();
}
}
exit (0);
}
#include <stdio.h>
#include <stdlib.h>
/* Test arithmetics on bitfields. */
extern void abort (void);
......@@ -65,8 +68,10 @@ void test##S (void) \
r = fn1##S (a); \
if (x.i != s##S.i || x.j != s##S.j \
|| x.k != s##S.k || x.l != s##S.l \
|| ((v + a) & mask) != r) \
|| ((v + a) & mask) != r) { \
printf("abort '%s' 1\n", #S ); \
abort (); \
} \
v = myrnd (); \
a = myrnd (); \
s##S.k = v; \
......@@ -74,8 +79,10 @@ void test##S (void) \
r = fn2##S (a); \
if (x.i != s##S.i || x.j != s##S.j \
|| x.k != s##S.k || x.l != s##S.l \
|| ((((v + a) & mask) % 15) & mask) != r) \
|| ((((v + a) & mask) % 15) & mask) != r) {\
printf("abort '%s' 2\n", #S ); \
abort (); \
}\
v = myrnd (); \
a = myrnd (); \
s##S.k = v; \
......@@ -83,8 +90,10 @@ void test##S (void) \
r = fn3##S (a); \
if (x.i != s##S.i || x.j != s##S.j \
|| s##S.k != r || x.l != s##S.l \
|| ((v + a) & mask) != r) \
|| ((v + a) & mask) != r) { \
printf("abort '%s' 3\n", #S ); \
abort (); \
} \
}
#ifdef __powerpc64__
......
......@@ -12,24 +12,24 @@ long double LD = 10.0;
int a, b = 3;
static int d = 4;
int d = 4;
static float fadd(float a, float b)
float fadd(float a, float b)
{
return a + b;
}
static float fadd_m(float a)
float fadd_m(float a)
{
return a + F;
}
static int iadd(int a, int b)
int iadd(int a, int b)
{
return a + b + (a*b) + (a / d);
}
static int iadd_m(int a)
int iadd_m(int a)
{
return a + I;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment