Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

acosl is not in the std namespace?

Tags:

c++

c++11

According to cppreference, the function acosl should be in the std namespace : https://en.cppreference.com/w/cpp/numeric/math/acos

However, with gcc (or clang), the code below does not compile :

#include <cmath>                                                                 

int main()                                                                       
{                                                                                
        long double var = std::acosl(4.0);                                      
        return 0;                                                                
}

I get the following error message:

gay@latitude-7490:~$ g++ -std=c++11 test.cpp
test.cpp: In function 'int main()':
test.cpp:5:26: error: 'acosl' is not a member of 'std'; did you mean 'acosh'?
    5 |  long double truc = std::acosl( (long double)4.0);
      |                          ^~~~~
      |                          acosh

What am I missing ? Am I misreading cppreference ?

like image 479
Manon Avatar asked Mar 09 '20 16:03

Manon


1 Answers

This seems to be a libstdc++ bug.

cmath in libstdc++ doesn't just wrap an #include <math.h> in namespace std: it defines new functions that delegate to built-ins. I guess a definition wants adding to this source code. It was probably just an oversight when C++11 (via C99) introduced the function. (Though notice that the acos(long double __x) overload delegates to __builtin_acosl!)

In Clang, switching to libc++ resolves the issue. With libstdc++, using the global namespace version of acosl should also work.

You should raise a bug. I think it's covered by bug #79700.

like image 187
Asteroids With Wings Avatar answered Nov 14 '22 23:11

Asteroids With Wings