diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-02-01 21:26:53 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-02-01 21:26:53 +0100 |
commit | 44ccdb3c72fad6daf995c0354e3ab75a3260ca9c (patch) | |
tree | d18c370193aa1e29956bd46bd6a318ec9b6227b8 /nl | |
parent | d5d642a170cd29e60c4d1dacd18ac4c5a8f8becd (diff) |
Floats, bugfixes, small reorganisations
Diffstat (limited to 'nl')
-rw-r--r-- | nl/mandel.nl | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/nl/mandel.nl b/nl/mandel.nl new file mode 100644 index 0000000..cef9eb2 --- /dev/null +++ b/nl/mandel.nl @@ -0,0 +1,69 @@ +type int = i32; +type char = i8; +type string = ptr(char); + +extern func void(int) putchar; + +void printnum(int n) { + if (n < 0) { + putchar('-'); + n = -n; + } + if (n == 0) { + putchar('0'); + return; + } + while (n > 0) { + putchar('0' + n % 10); + n = n / 10; + } +} + +int maxiter; +double lbound; +double rbound; +double tbound; +double bbound; +double hincr; +double vincr; + +int mandeliter(double x, double y) { + double a = x; + double b = y; + double a2 = a * a; + double b2 = b * b; + int n = 0; + while (n < maxiter && a2 + b2 < 4) { + b = 2 * a * b + y; + a = a2 - b2 + x; + a2 = a * a; + b2 = b * b; + n = n + 1; + } + return n; +} + +int main() { + maxiter = 32; + lbound = -2.0; + rbound = 1.0; + tbound = 1.5; + bbound = -1.5; + // hincr = 0.03125; + hincr = 0.0625; + vincr = 0.0625; + + double y = tbound; + while (y >= bbound) { + double x = lbound; + while (x <= rbound) { + int niter = mandeliter(x, y); + printnum(niter); + putchar(' '); + x = x + hincr; + } + putchar('\n'); + y = y - vincr; + } + return 0; +} |