On 12/06/2011 23:37, bearophile wrote:
Andrei:

Don, instead of this fix, could be at best phase everything
built-in about complex out?

Two usages of complex numbers in the RosettaCode site.

Acommon place where you find complex numbers is to plot
Mandelbrot/Julia sets: http://rosettacode.org/wiki/Mandelbrot_set#D

import std.stdio, std.math;

void main() { enum maxIter = 1000; foreach (y; -39 .. 39) { foreach
(x; -39 .. 39) { auto c = y/40.0 - 0.5 + x/40.0i, z = 0.0 + 0.0i, i =
0; for (; i<  maxIter&&  abs(z)<  4; i++) z = z ^^ 2 + c; write(i ==
maxIter ? '#' : ' '); } writeln(); } }



Version using std.complex:

import std.stdio, std.complex;

void main() { enum maxIter = 1000; foreach (y; -39 .. 39) { foreach
(x; -39 .. 39) { auto c = Complex!double(y/40.0 - 0.5, x/40.0), z =
Complex!double(0, 0), i = 0; for (; i<  maxIter&&  z.abs()<  4; i++)
z = z ^^ 2 + c; write(i == maxIter ? '#' : ' '); } writeln(); } }


I think it's worth adding to std.complex module few examples of
usage, plus a complex() function so you are allowed to write (the
imaginary part defaults to zero if the real part is set to zero):
auto z = complex(5);

I seemed to think the plan for complex numbers was to do what happened with associative arrays, that is, keep the language syntax, but have the feature implemented in the library. Is this not the case?

--
Robert
http://octarineparrot.com/

Reply via email to