Name

lldiv - computes quotient and remainder of an integer division

Library

libc.lib

Synopsis

  #include <stdlib.h>
  lldiv_t lldiv (long long numer, long long denom);

Return values

The lldiv function returns a structure of type lldiv_t that contains two long long members named quot (quotient) and rem (remainder).

Detailed description

The lldiv function computes the value of numer divided by denom and returns the stored result in the form of the lldiv_t type.

The lldiv_t type is defined as:

typedef struct {
        long long quot; /* Quotient. */
        long long rem;  /* Remainder. */
} lldiv_t;



Examples

#include <stdlib.h>
#include <stdio.h>
#include <math.h> /* link to the math lib -libm */
 
int main( void )
{
 long long numer = pow(2, 40);
 long long denom = 3;
 
 /* call to lldiv */
 lldiv_t x = lldiv(-numer, denom);
 
 printf("Result-> \nQuotient = %ld \nRemainder = %ld", x.quot, x.rem);
                 
 long long exp_numer = (denom * x.quot) + x.rem;
  
 if( exp_numer == (-numer) )
    printf("\nExpected output");  
 else
    printf("Unexpected output");
  
 return 0;
}


Output

Result->
Quotient = -366503875925
Remainder = -1
Expected output



See also

div, ldiv, math

Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top