# C programming fmin,fminf and fminl math.h

In C programming the <math.h> fmax,fmaxf and fmaxl determine the manimum numeric values of their arguments.The declaration of the functions are given below.

1 float fmin(float x , float y);
2 double fmin(double x , double y);
3 long double fmin(long double x , long double y);
4 float fminf(float x , float y);
5 long double fminl(long double x , long double y);

Parameters:
x -The first argument.

y -The second argument.

Return type
floating point -The greater value of x and y is returned.

All the functions are the same,they compute the minimum numeric values of the arguments.The 1st,2nd and the 3rd function have the same name i.e.’fmin’.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) fmin is analogous to fmax.

ii) if x≤y,x is returned.

iii) If x is -∞ and y is some valid value ,-∞ is returned.If x is +∞ and y is some valid value ,y is returned.

iii) If one of the arguments is NAN,the other argument is returned.If one is NAN and the other ±∞ , ±∞ is returned.

Code example

double dx=1200 , dy=1201 , x1=10.00 , x2=10 ;

float fx=1200, fy=1201 ;

long double ldx=1200 , ldy=1201 ;

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

printf(“\n%lf”, fmin( x1 , x2) ) ;
printf(“\n%lf”, fmin( NAN , 90) ) ;

Output in Visual Studio ,

1200.000000
1200.000000
1200.000000
10.000000
90.000000

For the 5th output the first argument is NAN so the second argument which is a valid value is returned.

#### fminf

The ‘fminf‘ 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 ‘fminf‘ stands for float and it signify the parameter type and return type of the function.

Code example

float x=2e20 , y=2e20 ;

printf(“%f”, fmin( x , y) ); //Calls the 1st version
printf(“\n%f”, fminf( 2e20 , 2e20) ); Calls the 4th version

Output in Visual Studio,

200000004008175468544.000000
200000004008175468544.000000

#### fminl

The ‘fminl‘ 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 ‘fminl‘ stands for long double and it signify the parameter type and return type of the function.

Code example

long double x=2e20 , y=2e20 ;

printf(“%Lf”, fmin(x , y) ); //Calls the 3rd version
printf(“\n%Lf”, fminl(2e20 , 2e20) ); Calls the 5th version

Output in Visual Studio,

2000000000000000039769249677312.000000
2000000000000000039769249677312.000000

*Side Note

The fmin function may be defined as:

double fmin(double x , double y)
{ return ( islessequal(x , y) ||
isnan( y ) ) ? x : y;
}