Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

# What is fmaxf in C?

Samia Ishaque

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.

## 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.3$ and $y = 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

c

CONTRIBUTOR

Samia Ishaque 