Man Linux: Main Page and Category List

div, ldiv, lldiv, imaxdiv - compute quotient and remainder of an integer division

#include<stdlib.h>div_tdiv(intnumerator,intdenominator);ldiv_tldiv(longnumerator,longdenominator);lldiv_tlldiv(longlongnumerator,longlongdenominator);#include<inttypes.h>imaxdiv_timaxdiv(intmax_tnumerator,intmax_tdenominator);Feature Test Macro Requirements for glibc (seefeature_test_macros(7)):lldiv(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; orcc-std=c99

Thediv() function computes the valuenumerator/denominatorand returns the quotient and remainder in a structure nameddiv_tthat contains two integer members (in unspecified order) namedquotandrem. The quotient is rounded towards zero. The result satisfiesquot*denominator+rem=numerator. Theldiv(),lldiv(), andimaxdiv() functions do the same, dividing numbers of the indicated type and returning the result in a structure of the indicated name, in all cases with fieldsquotandremof the same type as the function arguments.

Thediv_t(etc.) structure.

SVr4, 4.3BSD, C89. The functionslldiv() andimaxdiv() were added in C99.

After div_t q = div(-5, 3); the valuesq.quotandq.remare -1 and -2, respectively.

abs(3),remainder(3)

This page is part of release 3.24 of the Linuxman-pagesproject. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2007-07-26