LLRINT(3POSIX)
πΈ LLRINT β POSIX Programmer's Manual, bestie edition πΈ
okay so real quick, this is llrint(3POSIX) from the POSIX Programmer's Manual. Buckle up, we're rounding floats and we're doing it with taste. π
β¨ PROLOG β¨
So this page? It's part of the POSIX Programmer's Manual, periodt.
Heads up bestie: the Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page if you wanna know how Linux actually behaves), or honestly the interface may not be implemented on Linux at all. Vibe check accordingly. π
π NAME π
llrint, llrintf, llrintl β round to the nearest integer value using the current rounding direction. That's the whole job. Iconic, honestly. π
π¦ SYNOPSIS π¦
#include <math.h>
long long llrint(double x);
long long llrintf(float x);
long long llrintl(long double x);
Three flavors, one destiny. π
π DESCRIPTION π
The functionality on this reference page is aligned with the ISO C standard. If anything here conflicts with the ISO C standard, that was not the intention β not even a little. This volume of POSIX.1β2017 defers to the ISO C standard. It's giving "the ISO C standard is the main character here." β¨
These functions shall round their argument to the nearest integer value, rounding according to the current rounding direction. (Yes, the rounding direction. It's a whole thing. It matters.)
Now, if you're an application that wants to actually check for error situations, here's the little ritual you do:
- set
errnoto zero - call
feclearexcept(FE_ALL_EXCEPT)
...and you do all that before calling these functions. Then on return, you look at it like this: if errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero β an error has occurred. Boom. Detected. π
π RETURN VALUE π
Upon successful completion, these functions shall return the rounded integer value. slay.
Now the messier scenarios, because math is dramatic:
- If
xisNaN, a domain error shall occur, and an unspecified value is returned. π - If
xis+Inf, a domain error shall occur and an unspecified value is returned. - If
xis-Inf, a domain error shall occur and an unspecified value is returned. - If the correct value is positive and too large to represent as a
long long, an unspecified value shall be returned. On systems that support the IEC 60559 Floating-Point option, a domain error shall occur; otherwise, a domain error may occur. - If the correct value is negative and too large to represent as a
long long, an unspecified value shall be returned. On systems that support the IEC 60559 Floating-Point option, a domain error shall occur; otherwise, a domain error may occur.
"unspecified value" is doing so much heavy lifting here and honestly it's the most Gen Z thing in this whole page. it's like, we're not gonna say. π
π₯ ERRORS π₯
These functions shall fail if:
- Domain Error β The
xargument isNaNorΒ±Inf, or the correct value is not representable as an integer.- If the integer expression
(math_errhandling & MATH_ERRNO)is non-zero, thenerrnoshall be set to[EDOM]. - If the integer expression
(math_errhandling & MATH_ERREXCEPT)is non-zero, then the invalid floating-point exception shall be raised.
- If the integer expression
These functions may fail if:
- Domain Error β The correct value is not representable as an integer.
- If the integer expression
(math_errhandling & MATH_ERRNO)is non-zero, thenerrnoshall be set to[EDOM]. - If the integer expression
(math_errhandling & MATH_ERREXCEPT)is non-zero, then the invalid floating-point exception shall be raised.
- If the integer expression
The following sections are informative. (i.e. they're the vibes section, not the rules section. still useful tho. π«Ά)
π§ EXAMPLES π§
None.
Yeah. Nothing. Not a single one. The audacity. π
β APPLICATION USAGE β
On error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other β like two besties who don't share a calendar β but at least one of them must be non-zero. That's the rule. β¨
π RATIONALE π
These functions provide floating-to-integer conversions. They round according to the current rounding direction. If the rounded value is outside the range of the return type, the numeric result is unspecified and the invalid floating-point exception is raised. And when they raise no other floating-point exception and the result differs from the argument, they raise the inexact floating-point exception. (Inexact! So real of them. π―)
πΈ FUTURE DIRECTIONS πΈ
None.
The future? Empty. Peaceful. Unbothered. π
π SEE ALSO π
feclearexcept()fetestexcept()lrint()
And from the Base Definitions volume of POSIX.1β2017: Section 4.20, Treatment of Error Conditions for Mathematical Functions, and <math.h>. π¦
π 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. (So like, if they disagree, the original wins. no arguments. periodt.)
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, bestie β brought to you by IEEE/The Open Group, dated 2017, under the manual LLRINT(3POSIX). go round some integers, stay in your current rounding direction, and drink water. 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