为什么我不能在 MinGW 12.2.0 和 C++11 上使用 std::atanf?

问题描述 投票:0回答:1

从规范https://en.cppreference.com/w/cpp/numeric/math/atan来看,似乎

std::atanf
存在于C++11上,但在godbolt上它说“atanf”不是“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;      
}

怎么了?请注意,我不想使用 atanhf。

c++ mingw std libstdc++ compiler-bug
1个回答
2
投票

这是一个长期存在的错误,已于 2023 年 11 月得到解决。请参阅 GCC Bug 79700 -

std::fabsf
std::fabsl
中缺少
<cmath>

std::atanf
位于 C++11 标准中,但在过去 12 年左右的时间里没有人愿意添加它。有些人还认为它不应该存在(请参阅链接的错误以获取更多讨论)。

暂时使用

std::atan
。 这是一个重载函数,接受
float
double
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)
© www.soinside.com 2019 - 2024. All rights reserved.