How to use fmaxl() in C

The fmaxl() function in C compares two numbers and returns the larger number.

To use the fmaxl() function, the program needs to include the header file math.h as shown below:

#include <math.h>

Prototype

The exact long double value is returned without being rounded.

Examples

The following code demonstrates how to use the fmaxl() function:

#include <stdio.h>
#include <math.h>
int main(void)
{
// Example 1
long double x = 3.678;
long double y = 9.345;
// get larger value
long double max = fmaxl(x,y);
printf("The larger value is %Lf.\n",max);
// Example 2
max = fmaxl(x, NAN);
printf("The larger value is %Lf.\n",max);
// Example 3
max = fmaxl(NAN, NAN);
printf("The larger value is %Lf.\n",max);
}

Explanation

Example 1

If the inputs to the fmaxl() function are two long double values, the function returns the larger value.

Example 2

If one input to the fmaxl() function is NAN and the second input is a long double value, the function returns the long double value.

Example 3

If both inputs are NAN, then the function returns NAN.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved