fabs()

The fabs function returns the absolute value of the floating point argument.

Syntax

std:fabs(n)

Example 1

Use fabs() to return the absolute value of -6.5:

#include <iostream>
#include <cmath>
int main ()
{
std::cout << std::fabs(-6.5) << "\n";
}
// Output: 6.5

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn C++ on Codecademy