C/C++ and Assembly Language Interface
Listing 1-2
demonstrates the Mandelbrot generator expressed in a simple
algorithm using the C++ library
Listing 1-2. Mandelbrot Generator Example — C++ code
#include <complex>
int iterate (complex<double> c, complex<double> z, int max)
{
int n;
for (n = 0; n<max && abs(z)<2.0; n++)
{
z = z * z + c;
}
return (n == max ? 0 : n);
}
Listing 1-3
shows a C version of the inner computational function of the
Mandelbrot generator extracts performance and programming penalties
(compared with the C++ version).
Listing 1-3. Mandelbrot Generator Example — C Code
int iterate (double creal, double cimag,
double zreal, double zimag, int max)
{
double real, imag;
int n;
real = zreal * zreal;
imag = zimag * zimag;
for (n = 0; n<max && (real+imag)<4.0; n++)
{
zimag = 2.0 * zreal * zimag + cimag;
zreal = real - imag + creal;
real = zreal * zreal;
imag = zimag * zimag;
}
return (n == max ? 0 : n);
}
1-178
complex
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
class:
for ADSP-219x DSPs
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?