ROUND(3POSIX)
π ROUND(3POSIX) π
okay bestie, quick heads up before we dive in β this is ROUND(3POSIX) from the POSIX Programmer's Manual, and this whole page is part of that. Real talk: the Linux implementation of this interface may differ (so go peek at the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π Not me warning you first thing, but here we are.
β¨ PROLOG β¨
So like. This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. Periodt. π
πΈ NAME πΈ
round, roundf, roundl β round to the nearest integer value in a floating-point format
it's giving "glow up your decimals" fr fr π¦
π SYNOPSIS π
#include <math.h>
double round(double x);
float roundf(float x);
long double roundl(long double x);
three icons, one job. we love to see it. π
π DESCRIPTION π
okay so first thing, important vibe check: the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1β2017 defers to the ISO C standard. so if you see a fight, ISO C wins, no cap.
Now the actual tea β β these functions shall round their argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction. yes, regardless. the current rounding direction could never. π
π₯ RETURN VALUE π₯
Upon successful completion, these functions shall return the rounded integer value. And the result shall have the same sign as x. slay, sign preserved. π«Ά
- If
xisNaN, aNaNshall be returned. (it said "I'm not doing that" and returned itself π) - If
xisΒ±0orΒ±Inf,xshall be returned. (untouched, unbothered, main character energy β¨)
π ERRORS π
No errors are defined. literally zero drama. iconic.
The following sections are informative.
π EXAMPLES π
None. that's it. that's the section. π
π APPLICATION USAGE π
okay listen, this one actually matters:
The integral value returned by these functions need not be expressible as an intmax_t. So please test the return value before assigning it to an integer type, to avoid the undefined results of an integer overflow. don't just yolo it into an int, bestie, I'm begging. π
Also β these functions may raise the inexact floating-point exception if the result differs in value from the argument. so it can be a lil messy, and that's allowed. π§
β RATIONALE β
None. no thoughts, head empty. πΈ
π¦ FUTURE DIRECTIONS π¦
None. the future is bright and also empty. β
π SEE ALSO π
feclearexcept()fetestexcept()
The Base Definitions volume of POSIX.1β2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, <math.h>
go read those too, iykyk π
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, babe π this one's brought to you by IEEE/The Open Group, dated 2017, and it's the ROUND(3POSIX) page. go forth and round responsibly. mwah. π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms