Udostępnij przez


imaxdiv

Oblicza iloraz i pozostałą część dwóch wartości całkowitych dowolnego rozmiaru jako pojedynczą operację.

Składnia

imaxdiv_t imaxdiv(
   intmax_t numer,
   intmax_t denom
);

Parametry

numer
Licznik.

denom
Mianownik.

Wartość zwracana

imaxdiv, wywoływany z argumentami typu intmax_t, zwraca strukturę typu imaxdiv_t , która składa się z ilorazu i reszty.

Uwagi

Funkcja imaxdiv dzieli numerdenom się, a tym samym oblicza iloraz i resztę. Struktura imaxdiv_t zawiera iloraz , intmax_tquoti resztę intmax_trem. Znak ilorazu jest taki sam jak znak cudzysłów matematycznych. Jego wartość bezwzględna jest największą liczbą całkowitą mniejszą niż wartość bezwzględna ilorazu matematycznego. Jeśli mianownik ma wartość 0, program kończy się komunikatem o błędzie.

Wymagania

Procedura Wymagany nagłówek
imaxdiv <inttypes.h>

Aby uzyskać więcej informacji o zgodności, zobacz Zgodność.

Przykład

// 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);
}

Podczas kompilowania, a następnie wywoływanego za pomocą parametrów 9460730470000000 8766wiersza polecenia polecenia , kod generuje następujące dane wyjściowe:

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

Zobacz też

Obsługa obliczeń matematycznych i zmiennoprzecinkowych
div
ldiv, lldiv