Welcome to Fractal Forums

Fractal Software => Programming => Topic started by: stigomaster on September 06, 2009, 01:26:30 PM




Title: Help with complex header file in c++?
Post by: stigomaster on September 06, 2009, 01:26:30 PM
I am currently trying to write a buddhabrot program, and I would very much like to use the standard library <complex> header. So I include it, I use namespace std, and still these lines produce errors.
Code:
    complex cc(0.0, 0.0);
    complex zz(0.0, 0.0);
    
    complex tl = complex(0);  // Top left
    complex br = complex(0);  // Bottom right

    switch SCREEN_W {
        case 1024:
            tl = complex(-2.36, -1.26);
            br = complex(1, 1.26);
            break;
        case 1280:
            tl = complex(-2.5, -1.25);
            br = complex(1.5, 1.25);
            break;
        case 800:
            tl = complex(-2.36, -1.26);
            br = complex(1, 1.26);
            break;
    }

The errors I receive are:
41 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp missing template arguments before "cc"
41 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp expected `;' before "cc"

Please give help to a young nerd on the ridge of despair.


Title: Re: Help with complex header file in c++?
Post by: lycium on September 06, 2009, 01:34:02 PM
it would be good if you could report the error msg and the line on which it occurs  O0


Title: Re: Help with complex header file in c++?
Post by: stigomaster on September 06, 2009, 01:42:22 PM
Well, I did right after I posted the initial question, see OP. The error messages are identical for every line containing "complex(_,_)" declarations. Additionally, the lines immediately following those lines gets an error message as well:
47 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp expected primary-expression before "double"
47 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp expected `;' before "double"

I am using Dev-C++ 4.9.9.2 and the Allegro game library.


Title: Re: Help with complex header file in c++?
Post by: lycium on September 06, 2009, 03:03:52 PM
the complex class is templated, so you'd like to define a type:

typedef complex<double> complex_d;

then you can use eg.

complex_d a(0, 0), b(0, sqrt(2)); // etc...


Title: Re: Help with complex header file in c++?
Post by: stigomaster on September 06, 2009, 06:59:34 PM
Code:
    complex_d tl (0);  // Top left
    complex_d br (0);  // Bottom right
   
    double redch  [SCREEN_W, SCREEN_H] = 0.0;  // Arrays for color channels
    double greench[SCREEN_W, SCREEN_H] = 0.0;
    double bluech [SCREEN_W, SCREEN_H] = 0.0;

The typedef surely removed a great deal of the error messages, but these lines following the complex declarations still report
Code:
expected primary-expression before "double"
expected `;' before "double"

Why can't the compiler just do whatever I want it to?


Title: Re: Help with complex header file in c++?
Post by: lycium on September 10, 2009, 02:22:24 PM
there are a few things to note here:

1. trying to assign a variable to an array won't work, you'd need a for-loop to assign each of the elements individually (or a memset call).
2. it's not a good idea to separate the R, G and B components into seperate arrays, rather make a "colour" class containing the 3 elements.
3. using double precision floating point for your components is "a little" excessive :P
4. rather index directly into a single-dimensional array instead of using 2d arrays.


Why can't the compiler just do whatever I want it to?
most people need psychoanalysts to work out what they actually, exactly want in a given situation ;) computers can only do as they're told of course, and there's not a lot of room for interpretation!


Title: Re: Help with complex header file in c++?
Post by: HPDZ on September 21, 2009, 11:14:00 PM
Why can't the compiler just do whatever I want it to?

Microsoft, I hear, was working on a psychic compiler. They abandoned it and focused their efforts on incorporating psychic techology into their Office products. So far they have only done it with outline numbering in Word, and initial results have been abysmal.