lround(3)

πŸ’– lround(3) β€” the "round it, but give me an actual integer" girlies πŸ’–

okay bestie so this is a page from the Library Functions Manual, and it's all about the lround family β€” the ones who take your float and hand you back a whole number, no decimal drama, no cap. ✨


πŸŽ€ NAME πŸŽ€

lround, lroundf, lroundl, llround, llroundf, llroundl β€” round to nearest integer


πŸ“š LIBRARY πŸ“š

Math library (libm, -lm)

like she lives in libm, so if you're linking, don't forget your -lm, bestie, or she's gonna ghost you. 🫢


✨ SYNOPSIS ✨

#include <math.h>

long lround(double x);
long lroundf(float x);
long lroundl(long double x);

long long llround(double x);
long long llroundf(float x);
long long llroundl(long double x);

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

All functions shown above:

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L

so yeah, you gotta define that or the compiler is gonna be like "who?? never heard of her." πŸ’€


πŸ’… DESCRIPTION πŸ’…

These functions round their argument to the nearest integer value, rounding halfway cases away from zero, regardless of the current rounding direction (see fenv(3)).

okay that's the tea right there β€” halfway cases go away from zero, always, no matter what your current rounding direction is doing. she does NOT check the vibe of fenv(3). she has her own agenda. periodt. πŸ‘‘

Note that unlike the round(3) and ceil(3), functions, the return type of these functions differs from that of their arguments.

that's literally the whole plot twist: she does not return the same type you handed her. that's the entire point of her existence. it's giving "i changed, bestie." πŸ¦‹


πŸ‘‘ RETURN VALUE πŸ‘‘

These functions return the rounded integer value.

If x is a NaN or an infinity, or the rounded value is too large to be stored in a long (long long in the case of the ll* functions), then a domain error occurs, and the return value is unspecified.

🚨 bestie listen β€” NaN, infinity, or a number so big it won't fit in a long (or long long for the ll* crew)? that's a domain error and the return value is unspecified. unspecified means don't trust it, do not pass go, do not collect. 😭

πŸ“ ERRORS πŸ“

See math_error(7) for information on how to determine whether an error has occurred when calling these functions.

The following errors can occur:

  • Domain error: x is a NaN or infinite, or the rounded value is too large β€” An invalid floating-point exception (FE_INVALID) is raised.

These functions do not set errno.

ngl, that last line is the one that gets people. no errno for you, so don't go checking it and feeling confused. πŸ™ˆ this is why math_error(7) exists, go read her.


🌈 ATTRIBUTES 🌈

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

  • Interface: lround(), lroundf(), lroundl(), llround(), llroundf(), llroundl()
  • Attribute: Thread safety
  • Value: MT-Safe

MT-Safe, meaning she's safe to hang with from multiple threads at once. multithreaded icon behavior, honestly. πŸ’œ


⭐ STANDARDS ⭐

C11, POSIX.1-2008.


🧚 HISTORY 🧚

glibc 2.1. C99, POSIX.1-2001.

she's been around. she's a legacy icon, a vintage queen, and she's still slaying. ✨


πŸ”₯ SEE ALSO πŸ”₯

ceil(3), floor(3), lrint(3), nearbyint(3), rint(3), round(3)

like her whole friend group, go say hi, they're all doing similar-but-different things and yes you have to know the difference, sorry bestie, that's the assignment. πŸ’–


🌸 cute lil sign-off: this page is from Linux man-pages 6.20, dated 2026-02-08, and it's all about lround(3) β€” round to nearest integer, halfway cases away from zero, and that's on lround(3) πŸ’…πŸŽ€πŸ¦‹
πŸ“¦ 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: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms