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