C++ cmath abs() function
Example
Return the absolute (positive) value of different numbers:
cout << abs(-4.7);
cout << abs(4.7);
cout << abs(3);
Try it Yourself »
Definition and Usage
The abs()
function returns the absolute (positive) value of a number.
The abs()
function is defined in the
<cmath>
header file.
Syntax
One of the following:
double abs(double number);
float abs(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 double or float value representing the absolute value of the specified number. |
---|