-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandelbrot.c
63 lines (51 loc) · 1.46 KB
/
mandelbrot.c
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
54
55
56
57
58
59
60
61
62
63
/* The Computer Language Benchmarks Game
* http://benchmarksgame.alioth.debian.org/
contributed by Greg Buchholz
for the debian (AMD) machine...
compile flags: -O3 -ffast-math -march=athlon-xp -funroll-loops
for the gp4 (Intel) machine...
compile flags: -O3 -ffast-math -march=pentium4 -funroll-loops
*/
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
int w, h, bit_num = 0;
char byte_acc = 0;
int i, iter = 50;
double x, y, limit = 2.0;
double Zr, Zi, Cr, Ci, Tr, Ti;
w = h = atoi(argv[1]);
printf("P4\n%d %d\n",w,h);
for(y=0;y<h;++y)
{
for(x=0;x<w;++x)
{
Zr = Zi = Tr = Ti = 0.0;
Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0);
for (i=0;i<iter && (Tr+Ti <= limit*limit);++i)
{
Zi = 2.0*Zr*Zi + Ci;
Zr = Tr - Ti + Cr;
Tr = Zr * Zr;
Ti = Zi * Zi;
}
byte_acc <<= 1;
if(Tr+Ti <= limit*limit) byte_acc |= 0x01;
++bit_num;
if(bit_num == 8)
{
putc(byte_acc,stdout);
byte_acc = 0;
bit_num = 0;
}
else if(x == w-1)
{
byte_acc <<= (8-w%8);
putc(byte_acc,stdout);
byte_acc = 0;
bit_num = 0;
}
}
}
}