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 x is NaN, a NaN shall be returned. (it said "I'm not doing that" and returned itself 😭)
  • If x is Β±0 or Β±Inf, x shall 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 πŸ’–


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. πŸ’‹