abs() vs fabs()

Hi,

I noticed that the C++ compiler (pgCC 10.3-0 64-bit target on x86-64 Linux -tp shanghai-64) behaves somewhat unexpectedly when trying to compile

#include <cmath>

int main()
{
   double a = 5.0;
   std::abs(a);
   return 0;
}

The error message

"test-fabs.cpp", line 6: error: more than one instance of overloaded function
          "std::abs" matches the argument list:
            function "abs(int)"
            function "std::abs(long double)"
            argument types are: (double)
     std::abs(a);

is thrown and no object created, as opposed to what, e.g., g++ does and what’s documented here http://www.cplusplus.com/reference/clibrary/cmath/abs/.
Anyone else with this?

Cheers,
Nico

Hi Nico,

What command line flags are you using? As is, the code compiles fine for me so I’m wondering if you’re using non-PGI header files or have added define flags.

  • Mat
% cat test.cpp
#include <cmath>

int main()
{
   double a = 5.0;
   std::abs(a);
   return 0;
}

% pgcpp -V10.3 test.cpp -tp=shanghai-64 
%