Use of fabs() with tgmath.h and the 20.7 compiler

I have this tiny program, which does not compile using pgcc:

#include <tgmath.h>

int main(){
double f;

f=fabs((double)1.0);
f=sqrt((double)2.0);

}

Compiling:

$ pgcc -c99 bla.c
"bla.c", line 7: error: identifier "cfabs" is undefined
  f=fabs((double)1.0);
    ^

"bla.c", line 7: error: identifier "cfabsf" is undefined
  f=fabs((double)1.0);
    ^

"bla.c", line 7: error: identifier "cfabsl" is undefined
  f=fabs((double)1.0);
    ^

"bla.c", line 5: warning: variable "f" was set but never used
  double f;
         ^

3 errors detected in the compilation of "bla.c".

The PGI 19.10 compiler still mentioned :

PGC-F-0249-#error -- "Unsupported compiler; you cannot use <tgmath.h>" (/usr/include/tgmath.h: 244)

while the PGI 20.4 compiler gives many warnings, but does compile:

"bla.c", line 7: warning: __real/__imag applied to real value
  f=fabs((double)1.0);

Is there something silly wrong in the code, or does the 20.7 compiler have an issue with the fabs() function?

Looks like a typo in our new tgmath.h.

If you’re able to you can fix the problem by editing the “compilers/include/tgmath.h” file and changing “cfabs, cfabsf, cfabsl" to “cabs, cabsf, cabsl".

If you’re unable to edit the “tgmath.h” file, you can wait for the 20.9 release where we’ll have this fixed, or add the following to your code, before including “tgmath.h”.

#define cfabs cabs
#define cfabsf cabsf
#define cfabsl cabsl

Thanks for the report.
Mat

1 Like