Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

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.

The `fmax()`

function in C++ is used to return the larger number among two arguments (`x`

and `y`

) passed to the function.

The `fmax()`

function is defined in the `<cmath>`

header file.

double fmax (double x, double y);float fmax (float x, float y);long double fmax (long double x, long double y);

Syntax

The `fmax()`

function takes two parameter values, `x`

and `y`

, which represent the first and second arguments of the function, respectively.

The `fmax()`

function returns the larger value among the `x`

and `y`

values.

#include <iostream>#include <cmath>using namespace std;int main(){double x = -2.05, y = -3.5, result;result = fmax(x, y);cout << "fmax(x, y) = " << result << endl;return 0;}

Implementing the fmax() function

We can see from the code above that the `fmax()`

function correctly returned `-2.05`

as the larger value when compared to `-3.5`

.

We can also use the `fmax()`

function to compute for the larger number between arguments of different data types, such as a `double`

and an `int`

.

#include <iostream>#include <cmath>using namespace std;int main(){// using different argument typesdouble x = 89.1, result;int y = 89;result = fmax(x, y);cout << "fmax(89.1, 89) = " << result << endl;return 0;}

Implementing the fmax() function for different argument types

We can see from the code above that the `fmax()`

correctly returned the `double`

(`89.1`

) as the larger value when compared to the `int`

(`89`

).

RELATED TAGS

functions

c++

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

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.

Keep Exploring

Related Courses