C fminimum_num() Function

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

Definition

In C, fminimum_num() returns the smaller of two double values. fminimum_num(8.0, 2.0) is 2.0. Negative zero is less than positive zero.

If exactly one argument is NaN, the function returns the other number. You get NaN only when both are NaN. This is C23-style math in <math.h>, so a newer C library may be required. Behavior is close to classic fmin().

Syntax

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

C
fminimum_num(8.0, 2.0);
CallWhat it does
fminimum_num(8.0, 2.0)Returns 2.0, the smaller value.
fminimum_num(NAN, 5.0)Prefers the number and returns 5.0.

Include <math.h>. On GCC, link with -lm. Needs C23 support. For NaN propagation, use fminimum() instead.

Library declarations
C
double fminimum_num(double x, double y);
float fminimum_numf(float x, float y);
long double fminimum_numl(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. If one is NaN, returns the other. NaN only if both are NaN.

C Examples

Example 1 — Smaller Signed Value

Ordinary numeric minimum of two doubles.

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

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

How It Works

  1. Include math.h. Declares fminimum_num.
  2. First pair. 2 is smaller than 8.
  3. Second pair. -3 is smaller than 1.
  4. Result type. Still a double.

Example 2 — Keep the Real Number

NaN on one side does not erase the other.

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

int main(void) {
    printf("%.1f\n", fminimum_num(NAN, 5.0));
    printf("%.1f\n", fminimum_num(-2.0, NAN));
    return 0;
}

How It Works

  1. NaN first. Returns 5.0.
  2. NaN second. Returns -2.0.
  3. Both NaN. Result would be NaN.
  4. Vs fminimum. fminimum would return NaN in both of these calls.

Example 3 — Pull Down to a Cap

Force a value not to rise above a maximum using min.

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

int main(void) {
    double temp = 42.0;
    double max_ok = 37.0;
    double held = fminimum_num(temp, max_ok);

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

How It Works

  1. Temp too high. 42 exceeds the cap.
  2. Take minimum. Result becomes 37.0.
  3. Already fine. A lower temp would stay as-is.
  4. Pattern. Classic upper clamp with a min helper.

Frequently Asked Questions

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

Next: fminimum()

Floating-point remainder after division.

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