Download "TMS320C6000 Optimizing C Compiler User's Guide"

Transcript
div/ldiv
div/ldiv
Syntax for C
Division
#include <stdlib.h>
div_t div(register int numer, register int denom);
ldiv_t ldiv(register long numer, register long denom);
Syntax for C++
#include <cstdlib>
div_t std::div(register int numer, register int denom);
ldiv_t std::ldiv(register long numer, register long denom);
Defined in
div.c in rts.src
Description
Two functions support integer division by returning numer (numerator) divided
by denom (denominator). You can use these functions to determine both the
quotient and the remainder in a single operation.
- The div function performs integer division. The input arguments are inte-
gers; the function returns the quotient and the remainder in a structure of
type div_t. The structure is defined as follows:
typedef struct
{
int quot;
int rem;
} div_t;
/* quotient
/* remainder
*/
*/
- The ldiv function performs long integer division. The input arguments are
long integers; the function returns the quotient and the remainder in a
structure of type ldiv_t. The structure is defined as follows:
typedef struct
{
long int quot;
long int rem;
} ldiv_t;
/* quotient
/* remainder
*/
*/
The sign of the quotient is negative if either but not both of the operands is
negative. The sign of the remainder is the same as the sign of the dividend.
9-54