Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

# What is fmax() in C?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 to double.

### Return Value

The function returns the larger of the two numbers as double datatype.

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

### Quiz

Q

What will fmax(-55.32, -55.321) return?

-55.32

-55.321

-55.320000

-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 4  printf("fmax(9, 7.8) = %f\n", fmax(9, 7.8)); //find max of 9 and 7.8   printf("fmax(20.3, 20.4) = %f\n", fmax(20.3, 20.4)); //find max of 20.3 and 20.4  printf("fmax(500.5, 500.5) = %f\n", fmax(500.5, 500.5)); //find max of 500.5 and 500.5  printf("fmax(1.2, nan) = %f\n", fmax(1.2, NAN)); //find max of 1.2 and nan  printf("fmax(nan, 1000.2) = %f\n", fmax(NAN, 1000.2)); //find max of nan and 1000.2   printf("fmax(nan, nan) = %f\n", fmax(NAN, NAN)); //find max of nan and nan   printf("fmax(-inf, nan) = %f\n", fmax(-INFINITY, NAN)); //find max of -inf and nan  printf("fmax(inf, nan) = %f\n", fmax(INFINITY, NAN)); //find max of inf and nan     return 0;}

RELATED TAGS

c

CONTRIBUTOR

Syed Muhammad Ali Mustafa 