xref: /csrg-svn/lib/libc/quad/moddi3.c (revision 53794)
153442Sbostic /*-
253442Sbostic  * Copyright (c) 1992 The Regents of the University of California.
353442Sbostic  * All rights reserved.
453442Sbostic  *
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  *
953442Sbostic  * %sccs.include.redist.c%
1053442Sbostic  */
1153442Sbostic 
1253442Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*53794Sbostic static char sccsid[] = "@(#)moddi3.c	5.3 (Berkeley) 06/02/92";
1453442Sbostic #endif /* LIBC_SCCS and not lint */
1553442Sbostic 
16*53794Sbostic #include "quad.h"
1753459Sbostic 
18*53794Sbostic /*
19*53794Sbostic  * Return remainder after dividing two signed quads.
20*53794Sbostic  *
21*53794Sbostic  * XXX
22*53794Sbostic  * If -1/2 should produce -1 on this machine, this code is wrong.
23*53794Sbostic  */
24*53794Sbostic quad
25*53794Sbostic __moddi3(quad a, quad b)
26*53794Sbostic {
27*53794Sbostic 	u_quad ua, ub, ur;
28*53794Sbostic 	int neg;
2953459Sbostic 
30*53794Sbostic 	if (a < 0)
31*53794Sbostic 		ua = -(u_quad)a, neg = 1;
32*53794Sbostic 	else
33*53794Sbostic 		ua = a, neg = 0;
34*53794Sbostic 	if (b < 0)
35*53794Sbostic 		ub = -(u_quad)b, neg ^= 1;
36*53794Sbostic 	else
37*53794Sbostic 		ub = b;
38*53794Sbostic 	(void)__qdivmod(ua, ub, &ur);
39*53794Sbostic 	return (neg ? -ur : ur);
4053442Sbostic }
41