The ldiv function

Name

ldiv -- 

Synopsis

#include <stdlib.h>

ldiv_t ldiv (long numer, long denom);

Description

The ldiv function computes the quotient and remainder of the division of the numerator numer by the denominator denom. If the division is inexact, the resulting quotient is the integer of lesser magnitude that is nearest to the algebraic quotient. If the result cannot be represented, the behavior is undefined: otherwise quot * denom + rem shall equal numer.

Returns

The ldiv function returns a structure of type ldiv_t comprising both the quotient and the remainder. The structure shall contain the following members, in either order:

long int quot; /* quotient */
long int rem;  /* remainder */

Implementation Notes

If denom is zero, or if numer is LONG_MIN and denom is -1, then fixed point overflow is detected. If the corresponding interrupt is enabled, then SIGFIXED_OVERFLOW is raised.