xref: /original-bsd/lib/libc/stdlib/ldiv.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Chris Torek.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #if defined(LIBC_SCCS) && !defined(lint)
12 static char sccsid[] = "@(#)ldiv.c	8.1 (Berkeley) 06/04/93";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <stdlib.h>		/* ldiv_t */
16 
17 ldiv_t
18 ldiv(num, denom)
19 	long num, denom;
20 {
21 	ldiv_t r;
22 
23 	/* see div.c for comments */
24 
25 	r.quot = num / denom;
26 	r.rem = num % denom;
27 	if (num >= 0 && r.rem < 0) {
28 		r.quot++;
29 		r.rem -= denom;
30 	}
31 	return (r);
32 }
33