round(3)

🌸 round(3) β€” Library Functions Manual 🌸

okay bestie, sit DOWN, because today we're talking about round from the math library and it's honestly so much more chill than people think πŸ’…


✨ NAME ✨

round, roundf, roundl β€” round to nearest integer, away from zero


πŸ“š LIBRARY πŸ“š

Math library (libm, -lm)

like, if you forget the -lm you're gonna have a bad time, fr fr 🫢


✨ SYNOPSIS ✨

#include <math.h>

double round(double x);
float roundf(float x);
long double roundl(long double x);

🧚 Feature Test Macro Requirements for glibc (see feature_test_macros(7)) 🧚

round(), roundf(), roundl():
    _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L

πŸ’– DESCRIPTION πŸ’–

So these functions round x to the nearest integer β€” BUT, and this is the iconique part, they round halfway cases away from zero. Regardless of the current rounding direction, okay? (that's fenv(3) business, iykyk). This is not the same as rint(3), which does the neat little round-to-nearest-even thing instead. different vibes entirely.

For example, round(0.5) is 1.0, and round(-0.5) is -1.0. ✨ see? away from zero. no ties broken to even here, we simply ✨leave✨


πŸŽ€ RETURN VALUE πŸŽ€

These functions return the rounded integer value. that's the whole thing, that's the tea πŸ“

If x is integral, +0, -0, NaN, or infinite, x itself is returned. she said "I'm already perfect" and honestly? correct πŸ‘‘


πŸ’€ ERRORS πŸ’€

No errors occur.

none. zero. not a single one. the vibe check is PASSED 😭✨


πŸ¦‹ ATTRIBUTES πŸ¦‹

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

  • Interface: round(), roundf(), roundl()
    • Attribute: Thread safety
    • Value: MT-Safe

multi-threaded besties, you are SAFE. go off πŸ”₯


⭐ STANDARDS ⭐

C11, POSIX.1-2008.


🌈 HISTORY 🌈

glibc 2.1. C99, POSIX.1-2001.

okay so here's the lore πŸ“– β€” POSIX.1-2001 contains text about overflow (which might set errno to ERANGE, or raise an FE_OVERFLOW exception). In practice, the result cannot overflow on any current machine, so this error-handling stuff was just nonsense. literally nonsense. (More precisely, overflow can happen only 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 was removed in POSIX.1-2008. good riddance honestly πŸ™ˆ

⚠️ PSA bestie: If you want to store the rounded value in an integer type, you probably want to use one of the functions described in lround(3) instead. do NOT come for me when round() returns a double and you wanted an int. that's a you problem, and also a lround(3) problem.

πŸ‘€ SEE ALSO πŸ‘€

ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)


and that's the page, periodt πŸ’œ this was Linux man-pages 6.20, dated 2026-02-08, and it's the round(3) page β€” now go round some numbers away from zero like the main character you are πŸ‘‘βœ¨

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