DIV(3P)
π DIV(3P) β the POSIX Programmer's Manual, bestie edition π
Okay so real talk, this page lives in the POSIX Programmer's Manual, and it's called div β and yes she's serving quotient-and-remainder realness, we love her for that.
πΈ PROLOG
So this manual page is part of the POSIX Programmer's Manual, okay? And here's the thing β the Linux implementation of this interface may differ, so like, go check the corresponding Linux manual page for the details of Linux behavior if that's your situation. Or... the interface might not even be implemented on Linux at all. π Which is a vibe, honestly.
β¨ NAME
div β compute the quotient and remainder of an integer division π
π SYNOPSIS
#include <stdlib.h>
div_t div(int numer, int denom);
That's it, that's the whole girl. Short, sweet, iconic. β¨
π¦ DESCRIPTION
So first things first, bestie: everything described on this reference page is aligned with the ISO C standard. If there's any conflict between what's written here and what the ISO C standard says, that conflict is unintentional β no cap, nobody's trying to start drama. This volume of POSIX.1β2017 simply defers to the ISO C standard. Periodt.
Now, the actual tea π: the div() function shall compute the quotient and remainder of the division of the numerator numer by the denominator denom.
And here's the little detail that's lowkey important: if the division is inexact, the resulting quotient is the integer of lesser magnitude that is the nearest to the algebraic quotient. (Read that twice, it matters. π)
And if the result cannot be represented, the behavior is undefined β like, genuinely undefined, don't come crying to me, that's just the rules. Otherwise, though? Otherwise it's all good and:
quot*denom+rem shall equal numer
Math girlies stay winning. π₯
π RETURN VALUE
The div() function shall return a structure of type div_t, and that structure is carrying both the quotient and the remainder, because why would she make you do two calls when one will do. Slay.
The structure includes the following members, in any order:
int quot; /* quotient */
int rem; /* remainder */
Two little ints, doing the most. π«Ά
π ERRORS
No errors are defined.
The following sections are informative. (Yes, that's it, that's the whole error section. She's unbothered. She's thriving. β¨)
π§ EXAMPLES
None.
β APPLICATION USAGE
None.
π RATIONALE
None.
πΈ FUTURE DIRECTIONS
None.
π₯ SEE ALSO
ldiv()
And from the Base Definitions volume of POSIX.1β2017: <stdlib.h>
π COPYRIGHT
Okay so legal time, gotta give credit where credit is due, because these girlies earned it:
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.
And here's the important bit, so listen up: 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. Like, that's the final boss, that's who you listen to. π
The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Also: 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. So if you spot one, that's probably why. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
ngl that copyright section is giving lawyer main character energy, but we respect it π
And that's a wrap, bestie! This whole page came to you from IEEE/The Open Group, dated 2017, under the name DIV(3P). Go forth and divide responsibly, mwah ππβ¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms