www.delorie.com/djgpp/doc/libc/libc_524.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

ldiv

Syntax

 
#include <stdlib.h>

ldiv_t ldiv(long numerator, long denominator);

Description

Returns the quotient and remainder of the division numerator divided by denominator. The return type is as follows:

 
typedef struct {
  long quot;
  long rem;
} ldiv_t;

Return Value

The results of the division are returned.

Portability

ANSI/ISO C C89; C99
POSIX 1003.2-1992; 1003.1-2001

Example

 
ldiv_t l = ldiv(42, 3);
printf("42 = %ld x 3 + %ld\n", l.quot, l.rem);

ldiv(+40, +3) = { +13, +1 }
ldiv(+40, -3) = { -13, +1 }
ldiv(-40, +3) = { -13, -1 }
ldiv(-40, -3) = { +13, -1 }


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2004   by DJ Delorie     Updated Apr 2004