nextafter(3)

πŸ’– nextafter(3) β€” floating-point number manipulation πŸ’–

okay so bestie, welcome to the Math library (libm, -lm) page about the nextafter girlies. This is nextafter(3), and she's here to help you walk one tiny little step across the floating-point number line. literally the smallest step possible. no cap. πŸ¦‹


✨ NAME ✨

nextafter, nextafterf, nextafterl, nexttoward, nexttowardf, nexttowardl β€” floating-point number manipulation πŸ’…


πŸ“š LIBRARY πŸ“š

Math library (libm, -lm)


πŸŽ€ SYNOPSIS πŸŽ€

#include <math.h>

double nextafter(double x, double y);
float nextafterf(float x, float y);
long double nextafterl(long double x, long double y);

double nexttoward(double x, long double y);
float nexttowardf(float x, long double y);
long double nexttowardl(long double x, long double y);

🌸 Feature Test Macro Requirements for glibc (see feature_test_macros(7)): 🌸

nextafter():

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
    || _XOPEN_SOURCE >= 500
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

nextafterf(), nextafterl():

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

nexttoward(), nexttowardf(), nexttowardl():

_XOPEN_SOURCE >= 600 || _ISOC99_SOURCE
    || _POSIX_C_SOURCE >= 200112L

πŸ‘‘ DESCRIPTION πŸ‘‘

So nextafter(), nextafterf(), and nextafterl() hand you back the next representable floating-point value that comes after x, but only if you're heading in the direction of y. it's giving "one single step, but make it mathematically legal". 🫢

And if y is less than x? Then these functions turn around and give you the largest representable number less than x. so they walk backwards too, iconic.

If x equals y, the functions just return y. like okay, no movement, we're staying put. 🧘

Now the nexttoward(), nexttowardf(), and nexttowardl() girlies do exactly the same thing as their corresponding nextafter() functions β€” except they take a long double as their second argument. that's the whole difference. that's it. periodt.


πŸ”₯ RETURN VALUE πŸ”₯

On success, these functions return the next representable floating-point value after x in the direction of y. slay.

If x equals y, then y (cast to the same type as x) is returned. so keep that cast in mind bestie, it matters.

If x or y is a NaN, a NaN is returned. πŸ’€

If x is finite, and the result would overflow, a range error occurs, and the functions return HUGE_VAL, HUGE_VALF, or HUGE_VALL, respectively, with the correct mathematical sign. that's the dramatic exit.

If x is not equal to y, and the correct function result would be subnormal, zero, or would underflow, a range error occurs, and either the correct value (if it can be represented), or 0.0, is returned.


😭 ERRORS 😭

Wanna know how to tell whether an error even happened when you called these? Go read math_error(7). it's your bestie for that. 🌈

The following errors can occur:

  • Range error: result overflow β€” errno is set to ERANGE. An overflow floating-point exception (FE_OVERFLOW) is raised.
  • Range error: result is subnormal or underflows β€” errno is set to ERANGE. An underflow floating-point exception (FE_UNDERFLOW) is raised.

πŸ¦‹ ATTRIBUTES πŸ¦‹

For an explanation of the terms used in this section, see attributes(7).

  • Interface: nextafter(), nextafterf(), nextafterl(), nexttoward(), nexttowardf(), nexttowardl() β€” Attribute: Thread safety β€” Value: MT-Safe

⭐ STANDARDS ⭐

C11, POSIX.1-2008.

This function is defined in IEC 559 (and the appendix with recommended functions in IEEE 754/IEEE 854). very official of her. πŸ‘‘


🌈 HISTORY 🌈

C99, POSIX.1-2001.


πŸ’€ BUGS πŸ’€

In glibc 2.5 and earlier, these functions do not raise an underflow floating-point (FE_UNDERFLOW) exception when an underflow occurs. so if you're on ancient glibc, don't come for her about the missing exception, okay?

Before glibc 2.23 these functions did not set errno. crying in legacy code fr fr. 😭


πŸŽ€ SEE ALSO πŸŽ€

nearbyint(3)


and that's the whole page, bestie β€” this was nextafter(3) from the Linux man-pages 6.20, dated 2026-02-08. drink some water, compile with -lm, and go take the tiniest step imaginable toward your dreams. mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms