Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useless code in libEM/emdata_transform.cpp #459

Open
jcbollinger opened this issue Apr 10, 2020 · 0 comments
Open

Useless code in libEM/emdata_transform.cpp #459

jcbollinger opened this issue Apr 10, 2020 · 0 comments

Comments

@jcbollinger
Copy link
Contributor

This is libEM/emdata_transform.cpp:1242-1245:

				float k2 = (float)(kx*kx+ky*ky);
				if (k2==0) { continue;}
				float phiK =0;
				if (k2>0) phiK= jxjyatan2[ (ky+Mid-1)*End + kx+Mid-1];  phiK= atan2((float)ky,(float)kx);

I observe first that unless the computation of k2 overflows, it never produces a negative value, and that if it produces exactly zero then the last two lines are not reached.

In that case, it is not necessary to check explicitly at line 1245 whether k2 exceeds 0. More significantly, however, the value copied into phiK from jxjyatan2 is always immediately overwritten by the result of calling atan2(). This probably constitutes only a trivial performance problem as long as the computed index into jxjyatan2 is a valid one, but it begs the question of whether something else was intended here.


An analogous computation of phiQ appears deeper in the same loop nest, at lines 1255-1258. Comments analogous to the above apply to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant