What is fmin() in C?

fmin() is a C library function that returns the smaller numeric value of its two arguments.

Library

#include<math.h>

Declaration

Following is the declaration of fmin() where x and y are the floating-point values to be compared:

double fmin(double x, double y);

Note: An integer can also be passed as a parameter to fmin(), but will be implicitly cast to double datatype.

Return value

The function returns the smaller number of the two numbers as double.

  • If one argument is NANnot a number, the other one is returned.
  • If both arguments are NAN, NAN is returned.

Code

The code below runs the fmin() function on different examples:

#include<stdio.h>
#include<math.h>
int main() {
printf("fmin(3, 4) = %f\n", fmin(3, 4)); //find min of 3 and 4
printf("fmin(9, 7.8) = %f\n", fmin(9, 7.8)); //find min of 9 and 7.8
printf("fmin(20.3, 20.4) = %f\n", fmin(20.3, 20.4)); //find min of 20.3 and 20.4
printf("fmin(500.5, 500.5) = %f\n", fmin(500.5, 500.5)); //find min of 500.5 and 500.5
printf("fmin(1.2, nan) = %f\n", fmin(1.2, NAN)); //find min of 1.2 and nan
printf("fmin(nan, 1000.2) = %f\n", fmin(NAN, 1000.2)); //find min of nan and 1000.2
printf("fmin(nan, nan) = %f\n", fmin(NAN, NAN)); //find min of nan and nan
printf("fmin(-inf, nan) = %f\n", fmin(-INFINITY, NAN)); //find min of -infinity and nan
printf("fmin(inf, nan) = %f\n", fmin(INFINITY, NAN)); //find min of infinity and nan
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved