xref: /csrg-svn/lib/libc/stdlib/ldiv.c (revision 61180)
142133Sbostic /*
2*61180Sbostic  * Copyright (c) 1990, 1993
3*61180Sbostic  *	The Regents of the University of California.  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*61180Sbostic static char sccsid[] = "@(#)ldiv.c	8.1 (Berkeley) 06/04/93";
1342133Sbostic #endif /* LIBC_SCCS and not lint */
1442133Sbostic 
1542133Sbostic #include <stdlib.h>		/* ldiv_t */
1642133Sbostic 
1742133Sbostic ldiv_t
ldiv(num,denom)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;
2748142Storek 	if (num >= 0 && r.rem < 0) {
2848142Storek 		r.quot++;
2948142Storek 		r.rem -= denom;
3042133Sbostic 	}
3142133Sbostic 	return (r);
3242133Sbostic }
33