fabsf 是 C++11 中 std 命名空间的一部分吗?
Is fabsf part of the std namespace in C++11?
页面 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++ 错误,在以后的版本中会修复吗?
cppreference 似乎不正确。看起来这是为 C++17 添加的,因为它 added to the draft in 2016 with the title [numerics] Apply P0175 (C Synopses)
and we can see p0175r1 确实添加了:
float fabsf(float x);
libc++ status does not indicate a status for p0175r1
so that would indicate that it does not support these changes yet. I can't find a line item for the proposal in tjhe libstdc++ status page.
是的,fabsf
和来自 math.h
的所有其他 -f
/-l
函数是通过 cmath
中的 std
命名空间的一部分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)
然而,table 列出 cmath 的内容直到 2016 年才被忽略,当时
p0175r1 修复了所有此类 table 以使其符合标准。
p0175r1
Impact on the standard
The change is purely editorial.
页面 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++ 错误,在以后的版本中会修复吗?
cppreference 似乎不正确。看起来这是为 C++17 添加的,因为它 added to the draft in 2016 with the title [numerics] Apply P0175 (C Synopses)
and we can see p0175r1 确实添加了:
float fabsf(float x);
libc++ status does not indicate a status for p0175r1
so that would indicate that it does not support these changes yet. I can't find a line item for the proposal in tjhe libstdc++ status page.
是的,fabsf
和来自 math.h
的所有其他 -f
/-l
函数是通过 cmath
中的 std
命名空间的一部分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)
然而,table 列出 cmath 的内容直到 2016 年才被忽略,当时 p0175r1 修复了所有此类 table 以使其符合标准。
p0175r1
Impact on the standard
The change is purely editorial.