xref: /csrg-svn/lib/libc/stdlib/ldiv.c (revision 48142)
142133Sbostic /*
242133Sbostic  * Copyright (c) 1990 Regents of the University of California.
342133Sbostic  * All rights reserved.
442133Sbostic  *
542133Sbostic  * This code is derived from software contributed to Berkeley by
642133Sbostic  * Chris Torek.
742133Sbostic  *
842133Sbostic  * %sccs.include.redist.c%
942133Sbostic  */
1042133Sbostic 
1142133Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*48142Storek static char sccsid[] = "@(#)ldiv.c	5.2 (Berkeley) 04/16/91";
1342133Sbostic #endif /* LIBC_SCCS and not lint */
1442133Sbostic 
1542133Sbostic #include <stdlib.h>		/* ldiv_t */
1642133Sbostic 
1742133Sbostic ldiv_t
1842133Sbostic ldiv(num, denom)
1942133Sbostic 	long num, denom;
2042133Sbostic {
2142133Sbostic 	ldiv_t r;
2242133Sbostic 
2342133Sbostic 	/* see div.c for comments */
2442133Sbostic 
2542133Sbostic 	r.quot = num / denom;
2642133Sbostic 	r.rem = num % denom;
27*48142Storek 	if (num >= 0 && r.rem < 0) {
28*48142Storek 		r.quot++;
29*48142Storek 		r.rem -= denom;
3042133Sbostic 	}
3142133Sbostic 	return (r);
3242133Sbostic }
33