
div/ldiv
7-30
Division
div/ldiv
Syntax
#include <stdlib.h>
div_t
div
(int numer, denom);
ldiv_t
ldiv
(long numer, 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;
/* quotient
*/
int rem;
/* remainder
*/
} div_t;
-
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; /* quotient
*/
long int rem; /* remainder
*/
} ldiv_t;
If the division produces a remainder, the sign of the quotient is the same as the
algebraic quotient, and the magnitude of the resulting quotient is the largest
integer less than the magnitude of the algebraic quotient. The sign of the
remainder is the same as the sign of numer.
Because ints and longs are equivalent types in TMS320C2x/C2xx/C5x C,
these functions are also equivalent.
Example
int 1 = −10
int j = 3;
div_t result = div (i, j)
;
/* result.quot == −3 */
/* result.rem == −1 */
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...