xref: /csrg-svn/lib/libc/quad/divdi3.c (revision 53794)
153435Sbostic /*-
253435Sbostic  * Copyright (c) 1992 The Regents of the University of California.
353435Sbostic  * All rights reserved.
453435Sbostic  *
5*53794Sbostic  * This software was developed by the Computer Systems Engineering group
6*53794Sbostic  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7*53794Sbostic  * contributed to Berkeley.
8*53794Sbostic  *
953435Sbostic  * %sccs.include.redist.c%
1053435Sbostic  */
1153435Sbostic 
1253435Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*53794Sbostic static char sccsid[] = "@(#)divdi3.c	5.3 (Berkeley) 06/02/92";
1453435Sbostic #endif /* LIBC_SCCS and not lint */
1553435Sbostic 
16*53794Sbostic #include "quad.h"
1753459Sbostic 
18*53794Sbostic /*
19*53794Sbostic  * Divide two signed quads.
20*53794Sbostic  * ??? if -1/2 should produce -1 on this machine, this code is wrong
21*53794Sbostic  */
22*53794Sbostic quad
23*53794Sbostic __divdi3(quad a, quad b)
24*53794Sbostic {
25*53794Sbostic 	u_quad ua, ub, uq;
26*53794Sbostic 	int neg;
2753459Sbostic 
28*53794Sbostic 	if (a < 0)
29*53794Sbostic 		ua = -(u_quad)a, neg = 1;
30*53794Sbostic 	else
31*53794Sbostic 		ua = a, neg = 0;
32*53794Sbostic 	if (b < 0)
33*53794Sbostic 		ub = -(u_quad)b, neg ^= 1;
34*53794Sbostic 	else
35*53794Sbostic 		ub = b;
36*53794Sbostic 	uq = __qdivrem(ua, ub, (u_quad *)0);
37*53794Sbostic 	return (neg ? -uq : uq);
3853435Sbostic }
39