# div(), ldiv, lldiv, imaxdivcompute quotient and remainder of integer division

## SYNOPSIS

#include <stdlib.h>

div_t div(int numer, int denom);

ldiv_t div(long numer, long denom);

lldiv_t div(long long numer, long long denom);

#include <inttypes.h>

imaxdiv_t div(intmax_t numer, intmax_t denom);

## DESCRIPTION

The div() class of functions compute 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 the nearest to the algebraic quotient. If the result cannot be represented, the behavior is undefined. Otherwise, quotient * denom + remainder equals numer.

The div_t type is defined as:

typedef struct {
int quot; /* Quotient. */
int rem;  /* Remainder. */
} div_t;
The ldiv_t type is defined as:

typedef struct {
long quot; /* Quotient. */
long rem;  /* Remainder. */
} ldiv_t;
The lldiv_t type is defined as:

typedef struct {
long long quot; /* Quotient. */
long long rem;  /* Remainder. */
} lldiv_t;
The imaxdiv_t type is defined as:

typedef struct {
intmax_t quot; /* Quotient. */
intmax_t rem;  /* Remainder. */
} imaxdiv_t;

## PARAMETERS

numer

Is the numerator.

denom

Is the denominator.

## RETURN VALUES

The div() function returns a structure of type div_t, comprising both the quotient and the remainder. The structure contains the following members in either order:

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

## CONFORMANCE

ANSI/ISO 9899-1990.

MT-Safe.

None.

## AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition

PTC MKS Toolkit 10.3 Documentation Build 39.