Name already in use
cpp-docs / docs / c-runtime-library / reference / fabs-fabsf-fabsl.md
- Go to file T
- Go to line L
- Copy path
- Copy permalink
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
fabs , fabsf , fabsl
Calculates the absolute value of the floating-point argument.
x
Floating-point value.
The fabs functions return the absolute value of the argument x . There’s no error return.
| Input | SEH exception | _matherr exception |
|---|---|---|
| ± QNaN, IND | none | _DOMAIN |
C++ allows overloading, so you can call overloads of fabs if you include the <cmath> header. In a C program, unless you’re using the <tgmath.h> macro to call this function, fabs always takes and returns a double .
If you use the fabs macro from <tgmath.h> , the type of the argument determines which version of the function is selected. See Type-generic math for details.
By default, this function’s global state is scoped to the application. To change this behavior, see Global state in the CRT.
C Language: fabs function
(Absolute Value of Floating-Point Number)
In the C Programming Language, the fabs function returns the absolute value of a floating-point number.
Syntax
The syntax for the fabs function in the C Language is:
Parameters or Arguments
Returns
The fabs function returns the absolute value of a floating-point number represented by x.
Required Header
In the C Language, the required header for the fabs function is:
Applies To
In the C Language, the fabs function can be used in the following versions:
fabs, fabsf, fabsl, fabsd32, fabsd64, fabsd128
The functions with decimal floating point parameters are declared if and only the implementation predefines __STDC_IEC_60559_DFP__ (i.e. the implementation supports decimal floating point numbers).
Contents
[edit] Parameters
| arg | — | floating point value |
| arith | — | floating point or integer value |
[edit] Return value
If successful, returns the absolute value of arg ( \(\small |arg| \) |arg| ). The value returned is exact and does not depend on any rounding modes.
[edit] Error handling
This function is not subject to any of the error conditions specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
fabs, fabsf, fabsl, fabsd32, fabsd64, fabsd128
Функции с десятичными параметрами с плавающей запятой объявляются тогда и только тогда, когда реализация предопределяет __STDC_IEC_60559_DFP__ (т. е. реализация поддерживает десятичные числа с плавающей запятой).
Parameters
| arg | — | плавающая запятая |
| arith | — | значение с плавающей точкой или целое число |
Return value
В случае успеха возвращает абсолютное значение arg (\(\small |arg| \)|arg|). Возвращаемое значение является точным и не зависит ни от каких режимов округления.
Error handling
Эта функция не подвержена ни одному из условий ошибки, указанных в math_errhandling .
Если реализация поддерживает арифметику с плавающей запятой IEEE (IEC 60559),