xref: /csrg-svn/lib/libc/quad/moddi3.c (revision 54083)
153442Sbostic /*-
253442Sbostic  * Copyright (c) 1992 The Regents of the University of California.
353442Sbostic  * All rights reserved.
453442Sbostic  *
553794Sbostic  * This software was developed by the Computer Systems Engineering group
653794Sbostic  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
753794Sbostic  * contributed to Berkeley.
853794Sbostic  *
953442Sbostic  * %sccs.include.redist.c%
1053442Sbostic  */
1153442Sbostic 
1253442Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*54083Sbostic static char sccsid[] = "@(#)moddi3.c	5.4 (Berkeley) 06/19/92";
1453442Sbostic #endif /* LIBC_SCCS and not lint */
1553442Sbostic 
1653794Sbostic #include "quad.h"
1753459Sbostic 
1853794Sbostic /*
1953794Sbostic  * Return remainder after dividing two signed quads.
2053794Sbostic  *
2153794Sbostic  * XXX
2253794Sbostic  * If -1/2 should produce -1 on this machine, this code is wrong.
2353794Sbostic  */
2453794Sbostic quad
2553794Sbostic __moddi3(quad a, quad b)
2653794Sbostic {
2753794Sbostic 	u_quad ua, ub, ur;
2853794Sbostic 	int neg;
2953459Sbostic 
3053794Sbostic 	if (a < 0)
3153794Sbostic 		ua = -(u_quad)a, neg = 1;
3253794Sbostic 	else
3353794Sbostic 		ua = a, neg = 0;
3453794Sbostic 	if (b < 0)
3553794Sbostic 		ub = -(u_quad)b, neg ^= 1;
3653794Sbostic 	else
3753794Sbostic 		ub = b;
38*54083Sbostic 	(void)__qdivrem(ua, ub, &ur);
3953794Sbostic 	return (neg ? -ur : ur);
4053442Sbostic }
41