C nextdown() Function

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

Definition

In C, nextdown() returns the next representable floating-point value after x in the direction of negative infinity. It steps one ulp downward on the number line.

You pass one double. The result is a double. Include <math.h>. nextdown is newer (C23). Older compilers and libraries may not provide it yet—check your toolchain before you rely on it.

Think of it as “go one tiny step down.” For many hosts, nextdown(x) matches the idea of nextafter(x, -INFINITY). Prefer the standard name when your library supports C23.

Syntax

Pass the floating-point value. Start with this call.

C
nextdown(1.0);
CallWhat it does
nextdown(1.0);Returns the next double strictly less than 1.0.

Include <math.h>. On GCC, link with -lm. Confirm C23 support; some platforms still lack nextdown.

Library declarations
C
double nextdown(double x);
float nextdownf(float x);
long double nextdownl(long double x);

Parameters

ParameterDescription
xRequired. The double to step downward from.

Return Value

Return ValueDescription
Next lower doubleThe next representable value toward -∞.
Special casesBehavior for NaN and infinities follows the floating-point rules of your library.

C Examples

Example 1 — Basic Downward Step

Start at 1.0 and print the next smaller representable double.

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

int main(void) {
    double x = 1.0;
    double y = nextdown(x);

    printf("x = %.17g\n", x);
    printf("nextdown(x) = %.17g\n", y);
    return 0;
}

How It Works

  1. Include math.h. That declares nextdown when the library supports it.
  2. Start at 1.0. A simple binary floating value.
  3. Step down. nextdown(1.0) is the next double below 1.
  4. Print many digits. %.17g shows the tiny change.

Example 2 — Compare with nextafter

On supporting libraries, nextdown(x) agrees with stepping toward negative infinity.

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

int main(void) {
    double x = 2.5;
    double a = nextdown(x);
    double b = nextafter(x, -INFINITY);

    printf("nextdown   = %.17g\n", a);
    printf("nextafter  = %.17g\n", b);
    printf("same? %s\n", a == b ? "yes" : "no");
    return 0;
}

How It Works

  1. Pick a value. 2.5 is a normal finite double.
  2. Call nextdown. One step toward -∞.
  3. Call nextafter. Same direction via an older API.
  4. Compare. Matching bits means the libraries agree.

Example 3 — Walk a Few Steps Down

Call nextdown in a small loop to move several ulps downward.

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

int main(void) {
    double x = 0.0;
    int i;

    for (i = 0; i < 3; i++) {
        x = nextdown(x);
        printf("step %d: %.17g\n", i + 1, x);
    }
    return 0;
}

How It Works

  1. Start at 0. Zero is the midpoint of signed zeros.
  2. First step. The next down value is a tiny negative subnormal.
  3. Keep stepping. Each call moves one more representable slot.
  4. Tiny numbers. Near zero, ulps are extremely small.

Frequently Asked Questions

nextdown(x) returns the next representable value after x toward negative infinity.
x is required. It is the double you want to step downward from.
A double that is the next lower representable value from x.
Include <math.h>. On GCC, link with -lm. You also need a C23-capable math library.
Not yet. It is newer (C23). Many older toolchains do not declare it. Check your docs or fall back to nextafter toward -INFINITY.

Next: nexttoward()

Move toward a long double direction argument, like nextafter.

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