C fmaximum() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, fmaximum() returns the maximum of two floating-point values. fmaximum(3.0, 7.0) is 7.0. It is a C23 / newer library API.

You pass two double values. The result is a double. Include <math.h>. On GCC, link with -lm and enable a C23 mode when needed.

Syntax

Pass both values. Start with this call.

C
fmaximum(3.0, 7.0);
CallWhat it does
fmaximum(3.0, 7.0)Returns 7.0, the maximum.
fmaximum(-1.0, -4.0)Returns -1.0, the larger (less negative) value.

Include <math.h>. On GCC, link with -lm. The C identifier is fmaximum (underscore spelling only if you use related forms like fmaximum_mag). This page URL uses the slug fmaximum.

Library declarations
C
double fmaximum(double x, double y);
float fmaximumf(float x, float y);
long double fmaximuml(long double x, long double y);

Parameters

ParameterDescription
xRequired. First value to compare.
yRequired. Second value to compare.

Return Value

Return ValueDescription
doubleThe maximum of x and y. If either argument is NaN, the result is NaN.

C Examples

Example 1 — Basic Maximum

Compare two ordinary numbers.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("%.1f\n", fmaximum(3.0, 7.0));
    printf("%.1f\n", fmaximum(-1.0, -4.0));
    return 0;
}

How It Works

  1. Include math.h. Needs a C23-capable library.
  2. Positive pair. Maximum is 7.
  3. Negative pair. Maximum is −1.
  4. Same idea as fmax. NaN rules differ.

Example 2 — Equal Inputs

When both sides match, the shared value is returned.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double a = 2.5;
    double b = 2.5;
    printf("%.1f\n", fmaximum(a, b));
    return 0;
}

How It Works

  1. Same numbers. a and b are both 2.5.
  2. Call fmaximum. Result is 2.5.
  3. No surprise. Equal inputs stay equal.
  4. Compile tip. Use a C23 flag such as -std=c23 when required.

Example 3 — NaN Propagates

Unlike fmax, a NaN argument makes fmaximum return NaN.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double n = nan("");
    double r = fmaximum(n, 4.0);

    if (isnan(r)) {
        printf("result is NaN\n");
    } else {
        printf("%.1f\n", r);
    }
    return 0;
}

How It Works

  1. Make a NaN. Use nan("").
  2. Call fmaximum. One side is NaN.
  3. Check with isnan. Result should be NaN.
  4. C23 behavior. This is a key difference from fmax.

Frequently Asked Questions

fmaximum() returns the maximum of two floating values. It is a C23 / newer library API.
x and y are required doubles to compare.
The maximum of x and y. If either argument is NaN, the result is NaN.
Include <math.h>. On GCC, link with -lm and use a C23 mode when needed.
fmax usually returns the numeric value when the other side is NaN. fmaximum propagates NaN. fmaximum is C23.

Next: fmin()

C23 maximum by magnitude of two floating-point values.

fmin() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful