imaxdiv

크기와 관계없이 한 번의 연산으로 두 정수 값의 몫과 나머지를 계산합니다.

구문

imaxdiv_t imaxdiv(
   intmax_t numer,
   intmax_t denom
);

매개 변수

numer
분자입니다.

denom
분모입니다.

반환 값

imaxdiv형식intmax_t의 인수를 사용하여 호출되며 몫과 re기본der로 구성된 형식 imaxdiv_t 의 구조를 반환합니다.

설명

imaxdiv 함수는 numerdenom으로 나눠서 몫과 나머지를 계산합니다. imaxdiv_t 구조체에는 몫인 intmax_tquot와 나머지인 intmax_trem이 포함됩니다. 몫의 부호는 수학 몫의 부호와 같습니다. 절대값은 수학 몫의 절대값보다 작은 가장 큰 정수입니다. 분모가 0이면 프로그램이 종료되고 오류 메시지가 표시됩니다.

요구 사항

루틴에서 반환된 값 필수 헤더
imaxdiv <inttypes.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

예시

// crt_imaxdiv.c
// Build using: cl /W3 /Tc crt_imaxdiv.c
// This example takes two integers as command-line
// arguments and calls imaxdiv to divide the first
// argument by the second, then displays the results.

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int main(int argc, char *argv[])
{
   intmax_t x,y;
   imaxdiv_t div_result;

   x = atoll(argv[1]);
   y = atoll(argv[2]);

   printf("The call to imaxdiv(%lld, %lld)\n", x, y);
   div_result = imaxdiv(x, y);
   printf("results in a quotient of %lld, and a remainder of %lld\n\n",
          div_result.quot, div_result.rem);
}

9460730470000000 8766의 명령줄 매개 변수를 사용하여 빌드된 다음 호출되면 코드는 다음 출력을 생성합니다.

The call to imaxdiv(9460730470000000, 8766)
results in a quotient of 1079252848505, and a remainder of 5170

참고 항목

수학 및 부동 소수점 지원
div
ldiv, lldiv