Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
lldiv.c File Reference
#include <stdlib.h>
Include dependency graph for lldiv.c:

Go to the source code of this file.

Functions

lldiv_t lldiv (long long numer, long long denom)
 Computes both the quotient and the remainder of the division of the numerator x by the denominator y. More...
 

Function Documentation

◆ lldiv()

lldiv_t lldiv ( long long  x,
long long  y 
)

Computes both the quotient and the remainder of the division of the numerator x by the denominator y.

Computes both the quotient and the remainder of the division of the numerator x by the denominator y. Computes quotient and remainder simultaneously. The quotient is the algebraic quotient with any fractional part discarded (truncated towards zero). The remainder is such that quot * y + rem == x.

Computes the quotient (the result of the expression x/y) and remainder (the result of the expression xy) simultaneously.

Parameters
xinteger values
yinteger values
Returns
If both the remainder and the quotient can be represented as objects of the corresponding type (int, long, long long, imaxdiv_t, respectively), returns both as an object of type
See also
div_t,
ldiv_t,
lldiv_t,
imaxdiv_t.

If either the remainder or the quotient cannot be represented, the behavior is undefined.

Definition at line 30 of file lldiv.c.

31 {
32  lldiv_t retval;
33 
34  retval.quot = numer / denom;
35  retval.rem = numer % denom;
36  if(numer >= 0 && retval.rem < 0)
37  {
38  retval.quot++;
39  retval.rem -= denom;
40  }
41  return (retval);
42 }
long long quot
Definition: stdlib.h:31
Division type for long long integers.
Definition: stdlib.h:29
long long rem
Definition: stdlib.h:32

References lldiv_t::quot, and lldiv_t::rem.