c++mingwstdlibstdc++compiler-bug

Why can't I use std::atanf on MinGW 12.2.0 and C++11?


From specs https://en.cppreference.com/w/cpp/numeric/math/atan, it seems std::atanf exist on C++11, but on godbolt it says 'atanf' is not a member of 'std':

#include <iostream>
#include <cmath>

int main()
{
    float sampleOverLoaded = 200.0f;
    float outputAtan = atanf(sampleOverLoaded);
    float outputAtanStd = std::atanf(sampleOverLoaded);
    std::cout << outputAtan << std::endl;    
    std::cout << outputAtanStd << std::endl;      
}

What's wrong? Notice I don't want to use atanhf.


Solution

  • This is a long-standing bug which has been resolved in November 2023 for GCC14. See GCC Bug 79700 - std::fabsf and std::fabsl missing from <cmath> .

    std::atanf is in the C++11 standard, but no one bothered adding it for the last 12 years or so. Some people also think it shouldn't exist (see the linked bug for more discussion).

    For the time being, use std::atan. It's an overloaded function which accepts float, double, and long double:

    float       atan ( float num );
    double      atan ( double num );
    long double atan ( long double num ); // (until C++23)
    
    /* floating-point-type */
      atan ( /* floating-point-type */ num ); // (since C++23)