Go to the first, previous, next, last section, table of contents.

ldiv---divide two long integers

Synopsis
#include <stdlib.h>
ldiv_t ldiv(long n, long d);

Description
Divide returning quotient and remainder as two integers in a structure ldiv_t.


Returns
The result is represented with the structure

 typedef struct
 {
  long quot;
  long rem;
 } ldiv_t;

where the quot field represents the quotient, and rem the remainder. For nonzero d, if `r = ldiv(n,d);' then n equals `r.rem + d*r.quot'.

When d is zero, the quot member of the result has the same sign as n and the largest representable magnitude.

To divide int rather than long values, use the similar function div.


Portability
ldiv is ANSI, but the behavior for zero d is not specified by the standard.

No supporting OS subroutines are required.



Go to the first, previous, next, last section, table of contents.