What is fmax() in C?
fmax() is a C library function that returns the larger numeric value of its two arguments.
Library
#include<math.h>
Declaration
Following is the declaration of fmax() where x and y are the floating-point values to be compared:
double fmax(double x, double y);
Note: Integer(s) can also be passed as a parameter(s) to
fmax(), but will be implicitly cast todouble.
Return Value
The function returns the larger of the two numbers as double datatype.
- If one argument is
, the other one is returned.NAN not a number - If both arguments are NAN, NAN is returned.
Quiz
Q
What will fmax(-55.32, -55.321) return?
A)
-55.32
B)
-55.321
C)
-55.320000
D)
-55.321000
Code
The below code runs the fmax() function on different example cases:
#include<stdio.h>#include<math.h>int main() {printf("fmax(3, 4) = %f\n", fmax(3, 4)); //find max of 3 and 4printf("fmax(9, 7.8) = %f\n", fmax(9, 7.8)); //find max of 9 and 7.8printf("fmax(20.3, 20.4) = %f\n", fmax(20.3, 20.4)); //find max of 20.3 and 20.4printf("fmax(500.5, 500.5) = %f\n", fmax(500.5, 500.5)); //find max of 500.5 and 500.5printf("fmax(1.2, nan) = %f\n", fmax(1.2, NAN)); //find max of 1.2 and nanprintf("fmax(nan, 1000.2) = %f\n", fmax(NAN, 1000.2)); //find max of nan and 1000.2printf("fmax(nan, nan) = %f\n", fmax(NAN, NAN)); //find max of nan and nanprintf("fmax(-inf, nan) = %f\n", fmax(-INFINITY, NAN)); //find max of -inf and nanprintf("fmax(inf, nan) = %f\n", fmax(INFINITY, NAN)); //find max of inf and nanreturn 0;}
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved