The div function

Name

div -- 

Synopsis

#include <stdlib.h>

div_t div (int numer, int denom);

Description

The div 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 div function returns a structure of type div_t comprising both the quotient and the remainder. The structure shall contain the following members, in either order:

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

Implementation Notes

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