C++ fmin()

Last Updated On Saturday 16th Apr 2022

The fmin() function takes two arguments and returns the smallest among them. If one of the argument is NaN, the other argument is returned , It is defined in <cmath> header file.

Syntax

	fmin(double x, double y)
	

Parameters

The fmin() takes two arguments.

  • x: The first argument
  • y: The second argument

Return value

Returns the minimum value among x and y.

fmin() prototype [As of C++ 11 standard]

	double fmin(double x, double y);
float fmin(float x, float y);
long double fmin(long double x, long double y);
Promoted fmin(Type1 x, Type2 y);
	

Since C++11, if any argument passed to fmin() is long double, the return type Promoted is long double. If not, the return type Promoted is double.

Example : C++ fmin()

	#include <stdio.h>
#include <math.h>

int main () {
  printf ("fmin (100.0, 1.0) = %f\n", fmin(100.0,1.0));
  printf ("fmin (-100.0, 1.0) = %f\n", fmin(-100.0,1.0));
  printf ("fmin (-100.0, -99.0) = %f\n", fmin(-100.0,-101.0));
  return 0;
}
	

Output

	fmin (100.0, 1.0) = 1.000000
fmin (-100.0, 1.0) = -100.000000
fmin (-100.0, -99.0) = -101.000000