Debian Codegraph @

benchmarks.larceny/src/mbrot.c

raw
1 /* MBROT -- Generation of Mandelbrot set fractal. */
2
3 #include <stdio.h>
4
5 #define FLOAT double
6
7 #define N 75
8
9 #define max_count 64
10 #define radius2 16.0
11
12 static int count (FLOAT r, FLOAT i, FLOAT step, int x, int y)
13 {
14 FLOAT cr = r + x*step;
15 FLOAT ci = i + y*step;
16 FLOAT zr = cr;
17 FLOAT zi = ci;
18 int c = 0;
19
20 while (c != max_count)
21 {
22 FLOAT zr2 = zr*zr;
23 FLOAT zi2 = zi*zi;
24
25 if (zr2+zi2 > radius2)
26 return c;
27
28 zi = 2.0*zr*zi + ci;
29 zr = (zr2-zi2) + cr;
30
31 c++;
32 }
33
34 return c;
35 }
36
37 static void mbrot (int *matrix, FLOAT r, FLOAT i, FLOAT step, int n)
38 {
39 int x, y;
40
41 for (y=n-1; y>=0; y--)
42 for (x=n-1; x>=0; x--)
43 matrix[y*n+x] = count (r, i, step, x, y);
44 }
45
46 static int test ()
47 {
48 int matrix[N*N];
49
50 mbrot (matrix, -1.0, -0.5, 0.005, N);
51
52 return matrix[0];
53 }
54
55 int main (int argc, char *argv[])
56 {
57 int i;
58 int result;
59
60 for (i=0; i<100; i++)
61 result = test ();
62
63 if (result != 5)
64 printf ("*** wrong result ***\n");
65
66 return 0;
67 }