<cmath> and namespace std

The following snippet does not compile with g++ v4.8.2:

Code:
#include <cmath>
int main()
{
  double m = std::fmax(2., 8.);
  m = std::abs(2.);
}

The command g++48 -std=c++11 asd.cpp gives this error:

Code:
asd.cpp: In function 'int main()':
asd.cpp:6:14: error: 'fmax' is not a member of 'std'
   double m = std::fmax(2., 8.);
              ^
asd.cpp:6:14: note: suggested alternative:
In file included from /usr/local/lib/gcc48/include/c++/cmath:44:0,
                 from asd.cpp:2:
/usr/include/math.h:270:8: note:   'fmax'
 double fmax(double, double) __pure2;
        ^

It seems, that abs is a member of the namespace std, but fmax is not. The version of the g++ is
Code:
g++48 (FreeBSD Ports Collection) 4.8.2 20130919 (prerelease)

I also have installed g++ v4.2.1 and v4.6.3. g++ v4.8.1 in Arch Linux and in MinGW compiles this code without errors. How should I fix this problem?
 
Well it seems like the overloading function
Code:
double fabs (T x);
was not ported/implemented on our C++11 library, so just use the C version directly.
 
I was more hoping that the problem may be in multiple interfering compiler versions and has therefore some simple solution. Could someone with lang/gcc48 try to compile the code in the first post and confirm that the other installations have the same problem?
 
Unless you need to deal with NaN safely, you could just use std::max from <algorithm> instead.

Code:
#include <algorithm>

int main(int argc, char **argv) {
  double m = std::max(2.0, 8.0);
  return 0;
}
 
FWIW:
Code:
[CMD=%]clang++ snippet.cc[/cmd]
snippet.cc:4:19: error: no member named 'fmax' in namespace 'std'
  double m = std::fmax(2., 8.);
             ~~~~~^
1 error generated.
It's not the compiler(s), it's the library.
 
Back
Top