CARM User's Guide

Discontinued

ldiv

Summary
#include <stdlib.h>

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

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

div

Example
#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);
}