C fminimum() Function

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

Definition

In C, fminimum() returns the smaller of two double values by numeric order. fminimum(8.0, 2.0) is 2.0. Negative zero is treated as less than positive zero.

If either argument is NaN, the result is NaN. That is the main difference from classic fmin(). This is a C23-style function in <math.h>, so you may need a newer C library.

Syntax

Pass two floating-point numbers. Start with this call.

C
fminimum(8.0, 2.0);
CallWhat it does
fminimum(8.0, 2.0)Returns 2.0, the smaller value.
fminimum(1.0, NAN)Returns NaN because one argument is NaN.

Include <math.h>. On GCC, link with -lm. Needs C23 math support. Prefer fmin() if you want the older “skip NaN” behavior.

Library declarations
C
double fminimum(double x, double y);
float fminimumf(float x, float y);
long double fminimuml(long double x, long double y);

Parameters

ParameterDescription
xRequired. First floating-point value.
yRequired. Second floating-point value.

Return Value

Return ValueDescription
doubleThe smaller argument, or NaN if either argument is NaN.

C Examples

Example 1 — Numeric Minimum

Choose the lower of two ordinary doubles.

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

int main(void) {
    printf("%.1f\n", fminimum(8.0, 2.0));
    printf("%.1f\n", fminimum(-1.0, -4.0));
    return 0;
}

How It Works

  1. Include math.h. Declares fminimum.
  2. Positive pair. 2 is smaller than 8.
  3. Negative pair. -4 is smaller than -1.
  4. No NaN here. Both inputs are normal numbers.

Example 2 — NaN Makes the Result NaN

Unlike fmin, a single NaN turns the answer into NaN.

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

int main(void) {
    double r = fminimum(3.0, NAN);

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

How It Works

  1. Call with NaN. Second argument is not a number.
  2. Propagation. fminimum returns NaN.
  3. Detect it. isnan confirms the result.
  4. Contrast. fmin(3.0, NAN) would keep 3.0.

Example 3 — Keep the Lower Bound

Track the smaller endpoint of a range.

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

int main(void) {
    double lo = 10.0;
    double hi = 4.5;
    double start = fminimum(lo, hi);

    printf("start = %.1f\n", start);
    return 0;
}

How It Works

  1. Two ends. Values may arrive in any order.
  2. Take fminimum. The smaller end is 4.5.
  3. Safe when ordered. Works even if lo and hi are swapped.
  4. Watch NaN. If either end is NaN, the start becomes NaN too.

Frequently Asked Questions

It returns the smaller of two floating-point values. If either is NaN, the result is NaN.
Both x and y are required.
The smaller double, or NaN if either argument is NaN.
Include <math.h>. Link with -lm on GCC. Needs a newer C library for C23.
fmin() prefers a number over NaN. fminimum() returns NaN if either argument is NaN.

Next: fmod()

Pick the value with the smaller magnitude (C23).

fmod() 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