Please Interpret a statement

Hi there. In the webpage

http://www.librow.com/articles/article-10 which is about Librow FFT one can read:

1
2
3
4
5
6
7
8
//   FORWARD FOURIER TRANSFORM, INPLACE VERSION
//     Data - both input data and output
//     N    - length of both input data and result
bool CFFT::Forward(complex *const Data, const unsigned int N)
{
   //   Check input parameters
   if (!Data || N < 1 || N & (N - 1))
      return false;


Data is an array of real values. N is an integer, typically < 100.

or this statement:

1
2
3
4
5
6
bool CFFT::Forward(const complex *const Input, complex *const Output,
   const unsigned int N)
{
   //   Check input parameters
   if (!Input || !Output || N < 1 || N & (N - 1))
      return false;


I don't understand the meaning of the statement I highlighted, actually, in reality I don't understand only this part:

N & (N - 1)

Thanks, - A.
Last edited on
FFTs require that the number of elements be a power of 2.

N & (N - 1)

This is a simple way to tell if N is a power of 2. If it is a power of 2, the result will be 0, otherwise it will be non-0.

This is easy to prove because any N that is not a power of 2 will have the high bit set in both N and in N - 1.
The last is the most fun. N & (N - 1)
It relates to a statement made in the linked article.
7. Final remarks

From all our considerations follows that length of input data for our algorithm should be power of 2.

That code is rejecting any input N which is not an exact power of 2.

http://stackoverflow.com/questions/4678333/n-n-1-what-does-this-expression-do
Thank you very much. I am aware of that (power of 2 requirement) but thought that in principle this condition can be neglected but that will result in a lengthier computations. Mine was 100. You've saved my day. - A.
I presume

! Data means an empty set, correct?

Thanks, - Alex.
Data is a pointer.
This test !Data verifies that this is not a null pointer. In effect it means there is no array being passed to the function.
Thank you, Chervil
The "!Data" check is a stupid check because it only tests one type of pointer problem (NULL pointer). It is best to not check this at all. There are many more ways in which Data can be "wrong" and not be 0. If you are calling an FFT function with one of the input or output pointer wrong, you deserve what's coming, not "false".
The "!Data" check is a stupid check because it only tests one type of pointer problem (NULL pointer). It is best to not check this at all.

Please express your opinions on a perfectly reasonable error test as an opinion and not as fact. If the convention is for a NULL pointer to represent an empty in/output set to avoid special treatment of NULL outside the function and/or be consistent with the design of other functions in the library, it would be a crime not to check it.
Topic archived. No new replies allowed.