rint(3)

πŸ’– rint(3) β€” round to nearest integer πŸ’–

okay bestie, welcome to rint(3), straight out of the Library Functions Manual ✨ this is the "pls just give me the nearest whole number but keep it in float format" page, and honestly? it's giving perfectionist-with-boundary-issues. let's get into it 🫢


🌸 NAME 🌸

nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl β€” round to nearest integer


πŸ“š LIBRARY πŸ“š

Math library (libm, -lm)

so like. yes. you gotta link the math lib. <hotpink>-lm</hotpink> at the end of your compile line, don't forget it, she's the whole reason any of this works πŸ’…


✨ SYNOPSIS ✨

#include <math.h>

double nearbyint(double x);
float nearbyintf(float x);
long double nearbyintl(long double x);

double rint(double x);
float rintf(float x);
long double rintl(long double x);

πŸ” Feature Test Macro Requirements for glibc (see feature_test_macros(7)) πŸ”

lowkey the lore dump nobody wants but everyone needs, so here it is, full and complete:

nearbyint(), nearbyintf(), nearbyintl():

_POSIX_C_SOURCE >= 200112L || _ISOC99_SOURCE

rint():

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

rintf(), rintl():

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

πŸ’« DESCRIPTION πŸ’«

okay so the whole family here rounds its argument to an integer value in floating-point format. not to an actual int. floating-point. very important, bestie, do not skip that part πŸ’€

nearbyint(), nearbyintf(), and nearbyintl() do their rounding using the current rounding direction (peep fesetround(3) if you don't know her) and β€” this is the iconic part β€” they do not raise the inexact exception. minding their own business. no drama. ✨

and when the current rounding direction is to nearest? these girlies round halfway cases to the even integer, in accordance with IEEE-754. classic banker's rounding behavior, she's precise, she's fair, she's not picking favorites 🌈

then we have rint(), rintf(), and rintl(). they do the same thing… but β€” and this is the plot twist β€” they will raise the inexact exception (FE_INEXACT, which you can check via fetestexcept(3)) whenever the result differs in value from the argument. so like. same energy, but she tells you about it. main character behavior honestly πŸ’…


πŸŽ€ RETURN VALUE πŸŽ€

These functions return the rounded integer value. that's it, that's the return. 🫢

and if x is already integral, or +0, or -0, or NaN, or infinite? then x itself comes right back to you. no touchy. no changes. she said "I'm already perfect" and she's right πŸ‘‘


πŸ’€ ERRORS πŸ’€

No errors occur.

literally none. zero. the drama-free queen of the math library besties πŸ˜­πŸ™ˆ


πŸ”₯ ATTRIBUTES πŸ”₯

for the full explanation of what these words even mean, go see attributes(7) β€” i'm not gonna re-explain the whole glossary, that's a different page's job πŸ’…

  • Interface: nearbyint(), nearbyintf(), nearbyintl(), rint(), rintf(), rintl() β€” Attribute: Thread safety β€” Value: MT-Safe

MT-Safe means you can call her from multiple threads at once and she will not cause problems. iconic behavior, zero notes 🌸


⭐ STANDARDS ⭐

C11, POSIX.1-2008.


πŸ¦‹ HISTORY πŸ¦‹

C99, POSIX.1-2001.

now, story time πŸ“– β€” SUSv2 and POSIX.1-2001 used to contain a whole paragraph about overflow (which might set errno to ERANGE, or raise an FE_OVERFLOW exception). and like… in practice the result cannot overflow on any current machine, so that error-handling stuff was honestly just nonsense. πŸ’€

(and if you want the nerdy receipts: overflow can only happen when the maximum value of the exponent is smaller than the number of mantissa bits. for the IEEE-754 standard 32-bit and 64-bit floating-point numbers, the maximum value of the exponent is 127 (respectively, 1023), and the number of mantissa bits including the implicit bit is 24 (respectively, 53).) πŸ“

this whole thing was removed in POSIX.1-2008, so we're free. periodt ✨

one more thing bestie, real talk: if you actually want to store the rounded value in an integer type, you probably want to use one of the functions described in lrint(3) instead. don't be out here converting by hand, that's not the vibe 🫢


🌈 SEE ALSO 🌈

ceil(3), floor(3), lrint(3), round(3), trunc(3)


and that's the whole page, no cap. go #include <math.h>, go link -lm, and go round some floats πŸ’–

okay byeeee, this was Linux man-pages 6.20, dated 2026-02-08, and the page is rint(3) β€” drink water, link your math lib, and slay πŸ’…πŸŽ€πŸ¦‹βœ¨

πŸ“¦ 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