Keil Logo


#include <stdlib.h>

ldiv_t ldiv (
  long num,    /* numerator */
  long den);   /* denominator */

The ldiv function divides numerator by denominator and calculates the mathematical quotient and remainder. If the denominator has a value of zero, the results of the division are undefined.

Return Value

The ldiv function returns an ldiv_t type that contains the quotient and remainder of the division.

See Also


#include <stdlib.h>
#include <stdio.h>   /* for printf */

void tst_ldiv(void) {
  ldiv_t lres;

  lres = ldiv(3456L, 2345L);              // Do division
  printf ("Division = %ld r%ld\n", lres.quot, lres.rem);

  if (lres.rem >= 2345L/2L) lres.quot++;  // Round off
  printf ("Round-Off Division = %ld\n", lres.quot);
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.