Here https://en.cppreference.com/w/cpp/numeric/math/fabs it says that std::fabs is defined since C++11. However, this program fails: > #include <cstdlib> > > int main() { > std::fabs(1.); > } > $ c++ -std=c++11 -o fabs fabs.cpp > fabs.cpp:5:7: error: no member named 'fabs' in namespace 'std' > std::fabs(1.); > ~~~~~^ FreeBSD 12.1-STABLE r359625
The link you provided says "Defined in header <cmath>", try that?
(In reply to Yuri Pankov from comment #1) The link says: Defined in header <cmath> Defined in header <cstdlib> (since C++17) Thank you for pointing this out. I changed the subject. std::fabs is only missing from <cstdlib> for C++17+. > #include <cstdlib> > > int main() { > std::fabs(1.); > } > $ c++ -std=c++17 -o fabs fabs.cpp > fabs.cpp:4:7: error: no member named 'fabs' in namespace 'std' > std::fabs(1.); > ~~~~~^ > 1 error generated.
(In reply to Yuri Victorovich from comment #2) Quoting: -------- Defined in header <cmath> Defined in header <cstdlib> (since C++17) float abs( float arg ); double abs( double arg ); long double abs( long double arg ); Defined in header <cmath> float fabs ( float arg ); float fabsf( float arg ); (since C++11) -------- I read it as only abs() being defined in <cstdlib> since c++17, and fabs()/fabsf() having their own preceding comment about being in <cmath>, no?
(In reply to Yuri Pankov from comment #3) Ah, I see. My bad, I mis-read it. Thank you for making this clear. Best, Yuri