Home >Backend Development >C++ >What does fabs mean in c++
fabs() function is a mathematical function in C that calculates the absolute value of a floating point number, removes the negative sign and returns a positive value. It accepts a floating point parameter and returns an absolute value of type double. For example, fabs(-5.5) returns 5.5. This function works with floating point numbers, whose accuracy is affected by the underlying hardware.
fabs() function in C
What is the fabs() function?
fabs() function is a mathematical function defined in the C standard library and is used to calculate the absolute value of floating point numbers. Absolute value represents the positive value of a number and removes the negative sign for negative numbers.
Usage:
fabs() function accepts a floating point parameter and returns its absolute value. The syntax is as follows:
<code class="cpp">double fabs(double num);</code>
Return value:
fabs() function returns a double type value, representing the absolute value of the parameter num.
Example:
<code class="cpp">#include <cmath> int main() { double num1 = -5.5; double num2 = 12.34; double abs_num1 = std::fabs(num1); // abs_num1 = 5.5 double abs_num2 = std::fabs(num2); // abs_num2 = 12.34 return 0; }</code>
Note:
The above is the detailed content of What does fabs mean in c++. For more information, please follow other related articles on the PHP Chinese website!