# C++ cmath fmin , fminf and fminl

The C++ <cmath> fmin,fminf and fminl determine the minimum numeric value of the argument.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 minimum of the two arguments is returned.

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

cout<< “fmin(23 , 0)=” << fmin(23 , 0) << endl;

/*Passing ∞ */
cout<< “fmin(-INFINITY , 9934)=” << fmin(-INFINITY , 9934) << endl;

/*passing NaN */
cout<< “fmin(NAN , 0)=” << fmin(NAN , 0) << endl;

Output

fmin(23 , 0)= 0
fmin(-INFINITY , 9934)= -inf
fmin(NAN , 0)= 0

#### fminf and fminl

i)The 4th version fminf is same as the 1st version float fmin(float , float) .The last character ‘f‘ in ‘fminf’ stands for ‘float’ which signify the argument type and return type of the function.

ii)The 5th version fminl is same as the 3rd version long double fmin(long double , long double).The last character ‘l‘ in ‘fminl’ stands for ‘long double’ which signify the argument type and return type of the function.

Code example

#include <typeinfo>

/*fminf */
cout<< “*fminf\n”;
float f=2 , f1=99;
cout<< typeid( fminf(2 , 99) ).name() << endl /*identify type of fminf returned value */
<< typeid( fmin(f , f1) ).name() << endl; /*identify type of fmin(float , float) returned value */

/*fminl*/
cout<< “*fminl\n”;
long double ld=2 , ld1=89;
cout<< typeid( fminl(2 , 89) ).name() << endl /*identify type of fminl returned value */
<< typeid( fmin(ld , ld1) ).name() << endl; /*identify type of fmin(long double , long double) returned value*/

Output

*fminf
f
f
*fminl
e (means ‘long double’)
e (means ‘long double’)

*Side Note

The fmin function may be defined as:

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