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 inlround(3)instead. do NOT come for me whenround()returns adoubleand you wanted anint. that's a you problem, and also alround(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
- 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