# C programming fdim , fdimf and fdiml math.h

1 float fdim(float x , float y);
2 double fdim(double x , double y);
3 long double fdim(long double x , long double y);
4 float fdim(float x , float y);
5 long double fdim(long double x , long double y);

In C programming the <math.h> fdim,fdimf and fdiml compute the positive difference between the two arguments.The declaration of the functions are given below.

Parameters:
x -The value from which the second(argument) value is to be subtracted.

y -The value which is use for subtraction.

Return type
floating point -The positive difference between x and y.

All the functions are the same,they compute the positive difference of the arguments.The 1st,2nd and the 3rd function have the same name i.e.’fdim’.The 4th and 5th function have different names.What does having a different names mean is explained in detail below.

Some points to note:

i) fdim follows certain rule.It returns the resultant value of ‘x-y‘ if x>y,and it gives +0 if x≤y.

ii) If x is +∞, ∞ is returned,if x is -∞, 0 is returned.

iii) If x is NaN , ‘nan’ is returned.

Code example

double dx=122.0 , dy=14 , x1=10.00 , x2=11 ;

float fx=122.0 , fy=14 ;

long double ldx=122.0 , ldy=14 ;

printf(“%lf”, fdim( dx , dy) ) ; //calls the 2nd version
printf(“\n%f”, fdim( fx , fy) ) ; //calls the 1st version
printf(“\n%Lf”, fdim( ldx , ldy) ) ;//calls the 3rd version

printf(“\n%lf”, fdim( x1 , x2) ) ;
printf(“\n%lf”, fdim( INFINITY , 90) ) ;

Output in Visual Studio ,

108.000000
108.000000
108.000000
0.000000
inf

For the 4th output x2>x1 so the returned value is 0.

#### fdimf

The ‘fdimf‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘fdimf‘ stands for float and it signify the parameter type and return type of the function.

Code example

float x=99.0 , y=100.0 ;

printf(“%f”, fdim( x , y) ); //Calls the 1st version
printf(“\n%f”, fdimf( 99.0 , 100.0) ); Calls the 4th version

Output in Visual Studio,

0.900000
0.900000

#### fdiml

The ‘fdiml‘ function is same as the 1st function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘fdiml‘ stands for long double and it signify the parameter type and return type of the function.

Code example

long double x=99.0 , y=100.0 ;

printf(“%Lf”, fdim( x , y) ); //Calls the s3rd version
printf(“\n%Lf”, fdiml( 99.0 , 100.0) ); Calls the 5th version

Output in Visual Studio,

0.900000
0.900000