lrint(3)
β¨ lrint(3) β your girl is here to round things π
okay bestie, so this is one of those pages from the Library Functions Manual (section 3, math girlie division) and it's genuinely so useful. We're talking lrint, lrintf, lrintl, llrint, llrintf, llrintl β the whole squad. Their entire personality? Rounding to the nearest integer. That's it. That's the job. π
πΈ NAME πΈ
lrint, lrintf, lrintl, llrint, llrintf, llrintl β round to nearest integer, no cap.
π LIBRARY π
It lives in the Math library β that's libm, and you link it with -lm. Don't forget the flag or it's giving linker tantrum π
π SYNOPSIS π
#include <math.h>
long lrint(double x);
long lrintf(float x);
long lrintl(long double x);
long long llrint(double x);
long long llrintf(float x);
long long llrintl(long double x);
See the pattern? f suffix = float, l suffix = long double, and the double-l squad returns a long long instead. It's giving consistent queen behavior β¨
π§ Feature Test Macro Requirements for glibc (peep feature_test_macros(7)) π§
For all the functions shown above, you need one of:
_ISOC99_SOURCE_POSIX_C_SOURCE >= 200112L
π¦ DESCRIPTION π¦
These functions round their argument to the nearest integer value, and they do it using the current rounding direction β which is the vibe set by fesetround(3). So like, they're not out here doing their own thing, they're following the room. π«
lowkey important: unlike the rint(3) family of functions, the return type of these functions differs from that of their arguments. Yes, that's a whole difference. Not a typo. Periodt.
β RETURN VALUE β
They return the rounded integer value. Slay.
BUT β and this is the serious part π¨ β if x is a NaN or an infinity, or the rounded value is too large to be stored in a long (or a long long for the ll* functions), then a domain error occurs, and the return value is unspecified. Unspecified bestie. Do not trust it. Do not build on it. π
π ERRORS π
Wanna know how to even tell if an error happened when you called these? Go read math_error(7), it explains the whole detective situation.
Here's the error that can occur:
- Domain error:
xis a NaN or infinite, or the rounded value is too large β an invalid floating-point exception (FE_INVALID) gets raised.
Also, and this is huge: these functions do not seterrno. So don't go staring aterrnowaiting for it to tell you something, because it will not. π
π ATTRIBUTES π
If you wanna know what all these terms even mean, attributes(7) has you covered.
lrint(),lrintf(),lrintl(),llrint(),llrintf(),llrintl()β Thread safety: MT-Safe.
That's right, the entire friend group is MT-Safe. Multithreaded icon behavior, no notes. π₯
π STANDARDS π
C11, POSIX.1-2008. Certified and standardized, as she should be.
π HISTORY π
- glibc 2.1.
- C99, POSIX.1-2001.
Been around since forever, still relevant, still rounding. Main character energy since day one.
π«Ά SEE ALSO π«Ά
Go read the whole family, they're all doing slightly different rounding things and honestly it's a whole lore drop. π
k that's the page bestie!! this one shipped in Linux man-pages 6.20, dated 2026-02-08. go round some numbers, stay MT-Safe, and don't forget to check FE_INVALID πβ¨
π¦ 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
- Copyright 2001, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms