From 44ccdb3c72fad6daf995c0354e3ab75a3260ca9c Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 1 Feb 2017 21:26:53 +0100 Subject: Floats, bugfixes, small reorganisations --- nl/mandel.nl | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 nl/mandel.nl (limited to 'nl') 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; +} -- cgit v1.2.3-70-g09d2