Everything

ldiv


Division (long type)

[Classification]

Standard library

[Syntax]

#include <stdlib.h>

ldiv_t ldiv(long n, long d);

[Return value]

The structure storing the result of the division is returned.

[Description]

This function is used to divide a value of long type.

This function calculates the quotient and remainder resulting from dividing numerator n by denominator d, and stores these two integers as the members of the following structure div_t.

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

 

quot the quotient, and rem is the remainder. If d is not zero, and if "r = div(n, d);", n is a value equal to
"r.rem + d * r.quot".

If d is zero, the resultant quot member has a sign the same as n and has the maximum size that can be expressed. The rem member is 0.