a shot of dev knowledge

RELATED TAGS

What is fmaxf in C?

Overview

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 );

Examples

Below is an example of how to use fmaxf(). Using an example of x=3.3x = 3.3 and y=2.7y = 2.7, 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:

  1. If x is Not a Number (NaN), fmaxf() will return y, and vice versa

  2. 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

RELATED COURSES
View all Courses
Related Courses
RELATED COURSES
View all Courses
Keep Exploring