imaxdiv

Calcula el cociente y el resto de dos valores enteros de cualquier tamaño como una sola operación.

Sintaxis

imaxdiv_t imaxdiv(
   intmax_t numer,
   intmax_t denom
);

Parámetros

numer
Numerador.

denom
Denominador.

Valor devuelto

imaxdiv, llamado con argumentos de tipo intmax_t, devuelve una estructura de tipo imaxdiv_t que comprende el cociente y el resto.

Comentarios

La función imaxdiv divide numer por denom y, por tanto, calcula el cociente y el resto. La estructura imaxdiv_t contiene el cociente, intmax_tquot y el resto, intmax_trem. El signo del cociente es el mismo que el del cociente matemático. Su valor absoluto es el entero más grande que sea menor que el valor absoluto del cociente matemático. Si el denominador es 0, el programa se cierra con un mensaje de error.

Requisitos

Routine Encabezado necesario
imaxdiv <inttypes.h>

Para obtener más información sobre compatibilidad, consulte Compatibilidad.

Ejemplo

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

Si se compila y se llama con los parámetros de línea de comandos de 9460730470000000 8766, el código genera esta salida:

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

Consulte también

Compatibilidad con matemáticas y punto flotante
div
ldiv, lldiv