gpt4 book ai didi

c++ - fabsf 是 C++11 中 std 命名空间的一部分吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:20:33 25 4
gpt4 key购买 nike

页面https://en.cppreference.com/w/cpp/numeric/math/fabs提到 std::fabsf 从 C++11 开始可用。但是,当我使用 G++ 6.3.0 编译甚至使用 std::fabsf 的最简单程序时,它说 fabsf 不是 std< 的成员.

#include <cmath>
int main()
{
return (int)std::fabsf(0.0f);
}

哪个是对的? G++ 6.3.0 没有将它包含在 std 中是错误的,还是上面的页面在 C++11 中将它作为 std 的一部分提及是错误的?

如果是 G++ 出错了,那会在以后的版本中修复吗?

最佳答案

是的,fabsf和所有其他-f/-l来自 math.h 的功能是 std 的一部分通过 cmath 命名空间在 C++11 中。它是在大约 2002 年添加的,当时 C++0x 重新基于 C99 标准库,这使得 [c.math]/4包括这些新功能。

[c.math]/4

The contents of these headers are the same as the Standard C library headers <math.h> and <stdlib.h> respectively, with the following changes:

(历史记录:添加所有 -f/-l 变体的意图在 C++03 中已经很明显,参见 LWG289 )

但是,直到 2016 年,才忽略了列出 cmath 内容的表格,当时 p0175r1修复了所有此类表格,使其符合标准。

p0175r1

Impact on the standard

The change is purely editorial.

关于c++ - fabsf 是 C++11 中 std 命名空间的一部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54027717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com