C++ <cmath> - fabs() Function
The C++ <cmath> fabs() function returns the absolute value (positive value) of the specified number. For example - absolute value of x will be |x|.
Syntax
double fabs (double x); float fabs (float x); long double fabs (long double x);
double fabs (double x); float fabs (float x); long double fabs (long double x); //additional overloads for integral types double fabs (T x);
Parameters
x |
Specify a number whose absolute value need to be determined. |
Return Value
Returns the absolute value (positive value) of the argument.
Example:
In the example below, fabs() function returns the absolute value (positive value) of the specified number.
#include <iostream> #include <cmath> using namespace std; int main (){ cout<<fabs(10)<<"\n"; cout<<fabs(-10)<<"\n"; cout<<fabs(-5.45)<<"\n"; cout<<fabs(-5.55)<<"\n"; return 0; }
The output of the above code will be:
10 10 5.45 5.55
❮ C++ <cmath> Library