Home  >  Article  >  Backend Development  >  What does fabs mean in c language?

What does fabs mean in c language?

藏色散人
藏色散人Original
2020-02-06 11:57:0544993browse

What does fabs mean in c language?

What does fabs in c language mean?

The fabs function is a function that finds the absolute value. Finding the absolute value of x is the same as the mathematical concept. The function prototype is extern float fabs(float x), and the usage is #include .

Recommended learning: c language video tutorial

Declaration of fabs() function: double fabs(double x). The parameter x is a floating point value, and this function returns the absolute value of x. The code example is as follows:

int main (){
int a, b;
a = 1234;
b = -344;
printf("The absolute value of %d is %lf", a, fabs(a));
printf("The absolute value of %d is %lf", b, fabs(b));
return(0);}

Compile and run the above program, which will produce the following results:

The absolute value of 1234 is 1234.000000
The absolute value of -344 is 344.000000

What does fabs mean in c language?

Extended information:

fabs The difference between () and abs():

(1) Different parameter objects

abs() takes the absolute value of the integer, while fabs() takes the absolute value of the floating point number.

(2) The function prototype is different:

int abs(int x)
double fabs(double x)

(3) The header file is different:

abs(): #include <stdlib.h>
fabs(): #include <math.h>

The above is the detailed content of What does fabs mean in c language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn