C++ cmath fabs() function
Example
Return the absolute (positive) value of different numbers:
cout << fabs(-4.7);
cout << fabs(4.7);
cout << fabs(3);
Try it Yourself »
Definition and Usage
The fabs() function returns the absolute (positive) value of a number.
The fabs() function is defined in the <cmath> header file.
Syntax
One of the following:
fabs(double number);
fabs(float number);
Parameter Values
| Parameter | Description |
|---|---|
| number | Required. Specifies a number. If the number is an integer type then it will be treated as a double. |
Technical Details
| Returns: | A float value (if the argument is float) or double value (in any other case) representing the absolute value of the specified number. |
|---|