在线文档教程
C++
数字 | Numerics

std::fabs

STD:ABS%28浮标%29,STD::FASS

Defined in header
Defined in header <cstdlib>(since C++17)
float abs( float arg (1)
double abs( double arg (2)
long double abs( long double arg (3)
Defined in header <cmath>
float fabs( float arg (4)
double fabs( double arg (5)
long double fabs( long double arg (6)
double fabs( Integral arg (7)(since C++11)

1-6%29计算浮点值的绝对值。arg...

的所有参数组合的一组重载或函数模板算术类型%284-6%29不包括在内.。如果有任何争论积分型,它被铸造成double.如果任何其他论点是long double,则返回类型为long double,否则就是double...

For integral arguments, the integral overloads of std::abs are likely better matches. If std::abs is called with an argument of type X such that std::is_unsigned::value is true and X cannot be converted to int by integral promotion, the program is ill-formed.(since C++17)

参数

arg-Value of a floating-point or Integral type

返回值

如果成功,则返回arg%28|arg|29%。返回的值是准确的,不依赖于任何舍入模式。

错误处理

中指定的任何错误条件都不受此函数的影响。数学[医]错误处理...

如果实现支持ieee浮点算法%28IEC 60559%29,

  • 如果参数为±0,则返回+0

  • 如果参数为±∞,则返回+∞

  • 如果参数为nan,则返回nan。

注记

在C++11和C++14之间,标准错误地要求std::abs返回整数类型的重载double.在C++17中,这一要求被缺陷报告2735...

二次

#include <iostream> #include <cmath> int main() { std::cout << "abs(+3.0) = " << std::abs(+3.0) << '\n' << "abs(-3.0) = " << std::abs(-3.0) << '\n'; // special values std::cout << "abs(-0.0) = " << std::abs(-0.0) << '\n' << "abs(-Inf) = " << std::abs(-INFINITY) << '\n'; }

二次

可能的产出:

二次

abs(+3.0) = 3 abs(-3.0) = 3 abs(-0.0) = 0 abs(-Inf) = inf

二次

另见

abs(int)labsllabs (C++11)computes absolute value of an integral value (|x|) (function)
copysign (C++11)copies the sign of a floating point value (function)
signbit (C++11)checks if the given number is negative (function)
abs(std::complex)returns the magnitude of a complex number (function template)
abs(std::valarray)applies the function std::abs to each element of valarray (function template)

c工厂文件

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/数值/数学/晶圆厂