imaxdiv() — Quotient and remainder for intmax_t
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
C99 |
both | z/OS® V1R7 |
Format
#define _ISOC99_SOURCE
#include <inttypes.h>
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
Compile requirement: Function imaxdiv() requires
long long to be available.
General description
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.
Returned value
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.
Example
#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
Related information
- inttypes.h
- ldiv()
- lldiv()