LDIV(3POSIX)

🌸 LDIV(3POSIX) 🌸

okay bestie, gather round, we're doing the POSIX Programmer's Manual today πŸ’… this one's called LDIV(3POSIX) and it's literally about dividing longs. yes. that's the whole vibe. let's go ✨


🫢 PROLOG 🫢

so like, real talk first: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β€” so if you're on Linux, pls consult the corresponding Linux manual page for the details of Linux behavior πŸ’€ β€” or honestly, the interface may not even be implemented on Linux at all. vibe check: check your platform, bestie.


✨ NAME ✨

ldiv, lldiv β€” compute quotient and remainder of a long division πŸ“


🌈 SYNOPSIS 🌈

#include <stdlib.h>

ldiv_t ldiv(long numer, long denom);
lldiv_t lldiv(long long numer, long long denom);

like, that's it. two little functions. iconic.


πŸ’– DESCRIPTION πŸ’–

okay so here's the tea: 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 β€” not me causing drama on purpose, I promise πŸ™ˆ. This volume of POSIX.1‐2017 defers to the ISO C standard. periodt.

These functions shall compute the quotient and remainder of the division of the numerator numer by the denominator denom. πŸŽ€

If the division is inexact, the resulting quotient is the long integer (for the ldiv() function) or long long integer (for the lldiv() function) of lesser magnitude that is the nearest to the algebraic quotient. like, it rounds toward zero, if that helps you picture it πŸ¦‹

⚠️ If the result cannot be represented, the behavior is undefined. no cap, that's the scary part. otherwise, quot * denom+rem shall equal numer. ✨

πŸ‘‘ RETURN VALUE πŸ‘‘

The ldiv() function shall return a structure of type ldiv_t, comprising both the quotient and the remainder. That structure shall include the following members, in any order:

long   quot;    /* Quotient */
long   rem;     /* Remainder */

The lldiv() function shall return a structure of type lldiv_t, comprising both the quotient and the remainder. That structure shall include the following members, in any order:

long long   quot;    /* Quotient */
long long   rem;     /* Remainder */

two structs, four members, all the division energy you could ever want πŸ’œ


πŸ’€ ERRORS πŸ’€

No errors are defined.

like... none. zero. it's giving flawless. 😭

The following sections are informative. (that's fancy speak for "not the actual spec, just vibes") 🧚


πŸŽ€ EXAMPLES πŸŽ€

None.


🌸 APPLICATION USAGE 🌸

None.


πŸ¦‹ RATIONALE πŸ¦‹

None.


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ”₯ SEE ALSO πŸ”₯

  • div()
  • The Base Definitions volume of POSIX.1‐2017, <stdlib.h>

okay this part is the legal bit and we do not skip it, bestie. here it is, verbatim, because facts are facts:

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 lil masterpiece comes to you from IEEE/The Open Group, dated 2017, filed under LDIV(3POSIX). go forth and divide your longs responsibly πŸ’–βœ¨πŸŽ€