This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Question about the failure of "abs" to compute the complex value's magnitude

Hello:

 

   I am trying to manipulate the complex values in CCSv5 and run in C6713 dsk.

 

 

   What confused me was that I added header file "complex.h" and called the function creal and cimag.  Both of them worked.
   But if i want to call abs to determine the magnitude of the complex number, it did not work properly.  It should incorrect values instead.

 

   Snapshot:

 

 

 

You see, the first and second was correct but the third one, it was supposed to be "5.0" but why it showed -1.0?

 

I really don't know why this weird problem happend? Is abs obsolete or changed according to the update of the lib?

 

Thank you

 

Yu

 

 

  • In C, abs() takes an "int" argument. cabs() takes a "double complex" argument. If type-generic math is available and enabled (by #include <tgmath.h>), then fabs() will take any floating-point scalar or complex argument, and expand to the "right" variant of the fabs[fl]() or cabs[fl]() functions. Does using cabs() make the final printout show 5.0?