The fmaxf()
function in C is defined in the <math.h>
header file. fmaxf()
takes two arguments (x
and y
) of type float as input and returns the larger of the two numbers. The function is defined in the <math.h>
header file as:
float fmaxf( float x, float y );
Below is an example of how to use fmaxf()
. Using an example of and , we use the fmaxf()
function to print the largest floating-point number.
#include<stdio.h>#include<math.h>int main() {float largest = fmaxf(3.3, 2.7);printf("The larger of the two numbers is: %f\n", largest);return 0;}
Below are the ways in which the results of the fmaxf()
function vary for different values of x
and y
:
If x
is Not a Number (NaN)
, fmaxf()
will return y
, and vice versa
If both inputs are NaN
, the return value is also NaN
The code below demonstrates these input values and their results:
#include<stdio.h>#include<math.h>int main() {printf("The larger of the two numbers if one is NAN is: %f\n", fmaxf(NAN, 2.7));printf("The larger of the two numbers if both are NAN is: %f\n", fmaxf(NAN, NAN));return 0;}
RELATED TAGS
CONTRIBUTOR