Standards / Extensions | C or C++ | Dependencies |
---|---|---|
C99 |
both | z/OS® V1R7 |
#define _ISOC99_SOURCE
#include <inttypes.h>
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
The imaxdiv() function computes numer / denom and numer % denom in a single operation. The imaxdiv function is similar to lldiv() and ldiv(). The only difference being that the return value is of type imaxdiv_t and those being passed in are of type intmax_t.
imaxdiv() returns a structure of type imaxdiv_t comprising both the quotient and the remainder. If either part of the result cannot be represented, the behavior is undefined. if the denominator is zero, a divide by zero exception is raised.
#define _ISOC99_SOURCE
#include <inttypes.h>
#include <stdio.h>
int main(void)
{
intmax_t num = 45;
intmax_t den = 7;
imaxdiv_t res;
printf("Original numerator: %jd and denominator: %jd "
,num,den);
res = imaxdiv(num,den);
printf("Quotient: %jd Remainder: %jd\n"
, res.quot,res.rem);
}
Output
Original numerator: 45 and denominator: -7 Quotient: -6 Remainder: 3