NAME
div, ldiv, lldiv, imaxdiv – return quotient and remainder from division
SYNOPSIS
Standard C Library (libc, -lc)
#include <stdlib.h>
div_t
div(int numer, int denom);
ldiv_t
ldiv(long numer, long denom);
lldiv_t
lldiv(long long numer, long long denom);
#include <inttypes.h>
imaxdiv_t
imaxdiv(intmax_t numer, intmax_t denom);
DESCRIPTION
The div(), ldiv(), lldiv(), and imaxdiv() functions compute the value of numer (the numerator) divided by denom (the denominator) and return the stored result in the form of the div_t, ldiv_t, lldiv_t, or imaxdiv_t types, respectively. These types are structs which contain two int, long, long long, or intmax_t members named quot (the quotient) and rem (the remainder).
STANDARDS
The div(), ldiv(), lldiv(), and imaxdiv() functions conform to ISO/IEC 9899:2024 (“ISO C23”) and IEEE Std 1003.1-2024 (“POSIX.1”).
HISTORY
The div() and ldiv() functions first appeared in 4.3BSD. The lldiv() and imaxdiv() functions first appeared in FreeBSD 5.0.