From: uche on
Can someone point me in the right direction to take the dependencies
out of the following code ?
for (i=0; i < m; i++)
{

n1 = n2;
n2 = n2 + n2;
e = -6.283185307179586/n2;
a = 0.0;

for (j=0; j < n1; j++)
{
c = cos(a);
s = sin(a);
a = a + e;

for (k=j; k < n; k=k+n2)
{

{
t1 = c*x[k+n1] - s*y[k+n1];
t2 = s*x[k+n1] + c*y[k+n1];
x[k+n1] = x[k] - t1;
y[k+n1] = y[k] - t2;
x[k] = x[k] + t1;
y[k] = y[k] + t2;
}

}
}
}

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Francis Glassborow on
uche wrote:
> Can someone point me in the right direction to take the dependencies
> out of the following code ?
> for (i=0; i < m; i++)
> {
>
> n1 = n2;
what are n1 and n2?
> n2 = n2 + n2;
why not write
n2 *= 2;
Any modern compiler should deal with that efficiently.

> e = -6.283185307179586/n2;
What is e and what is the significance of that constant?

> a = 0.0;
Where is a declared? Any reason it should not be declared here?

>
> for (j=0; j < n1; j++)
Where is j (and then k) declared?

> {
> c = cos(a);
> s = sin(a);
> a = a + e;
>
> for (k=j; k < n; k=k+n2)
Do you really have an 'n' in your code?
> {
>
> {
> t1 = c*x[k+n1] - s*y[k+n1];
> t2 = s*x[k+n1] + c*y[k+n1];
> x[k+n1] = x[k] - t1;
> y[k+n1] = y[k] - t2;
> x[k] = x[k] + t1;
> y[k] = y[k] + t2;
> }
>
> }
> }
> }
>

The whole of the above code is opaque by virtue of unhelpful names and
lack of declarations. C++ deliberately allows late declaration of local
variables to help avoid this kind of code. In addition const in C++
provides a compile time constant that makes manifest (named) constants
easy to provide.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]