fabs
The C++
fabs()
function returns the absolute value of the argument and it takes a single argument.It is defined in the <cmath> header file. Mathematically,fabs(num) = |num|
.
Syntax
fabs(double num);
Parameters
The
fabs()
function takes a one argument. The argument can be of
double
,
long double
or
float
type.
Return value
fabs()
- Returns the absolute value of num i.e.
|num|
fabs() prototype
double fabs(double num); float fabs(float num); long double fabs(long double num); // for integral type double fabs(T num);
std fabs
Note: The
fabs()
function is identical to the cmathabs()
function.
fabs function
Example : C++ fabs()
#include <iostream> #include <cmath> using namespace std; int main() { double num = -11.44, result; result = fabs(num); cout << "fabs(" << num << ") = |" << num << "| = " << result; return 0; }
Output
fabs(-11.44) = |-11.44| = 11.44