【问题标题】:acosl is not in the std namespace?acosl 不在 std 命名空间中?
【发布时间】:2020-03-10 01:54:41
【问题描述】:

根据cppreference,函数acosl应该在std命名空间中:https://en.cppreference.com/w/cpp/numeric/math/acos

但是,使用 gcc(或 clang),下面的代码无法编译:

#include <cmath>                                                                 

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

我收到以下错误消息:

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

我错过了什么?我误读了 cppreference 吗?

【问题讨论】:

  • GCC 的哪个版本?嗯,在GCC 4.9.2 中似乎可以重现
  • @CoryKramer 9.2 和 trunc 失败。 acosl 没有 std:: 成功。
  • 我不确定发生了什么,但acosl(4.0)std::acos(4.0l) 都可以工作。此外,添加 -stdlib=libc++ 使 std::acosl(4.0) 在 Clang 中工作。
  • 我认为这是一个 GCC 问题,或者至少是一个 libstdc++ 问题。代码与使用 libc++ 的 clang here 一起工作正常

标签: c++ c++11


【解决方案1】:

这似乎是一个 libstdc++ 错误。

libstdc++ 中的cmath 不只是在namespace std 中包装#include &lt;math.h&gt;:它定义了委托给内置函数的新函数。我想一个定义想要添加到this source code。当 C++11(通过 C99)引入该函数时,这可能只是一个疏忽。 (尽管注意到acos(long double __x) 重载委托给__builtin_acosl!)

在 Clang 中,切换到 libc++ 可以解决问题。对于 libstdc++,使用acosl 的全局命名空间版本也应该可以工作。

你应该raise a bug我认为它被bug #79700覆盖了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 2020-10-03
    • 2010-12-25
    • 2013-05-27
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多