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*54431Sbostic static char sccsid[] = "@(#)moddi3.c 5.5 (Berkeley) 06/25/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 */ 24*54431Sbostic quad_t 25*54431Sbostic __moddi3(a, b) 26*54431Sbostic quad_t a, b; 2753794Sbostic { 28*54431Sbostic u_quad_t ua, ub, ur; 2953794Sbostic int neg; 3053459Sbostic 3153794Sbostic if (a < 0) 32*54431Sbostic ua = -(u_quad_t)a, neg = 1; 3353794Sbostic else 3453794Sbostic ua = a, neg = 0; 3553794Sbostic if (b < 0) 36*54431Sbostic ub = -(u_quad_t)b, neg ^= 1; 3753794Sbostic else 3853794Sbostic ub = b; 3954083Sbostic (void)__qdivrem(ua, ub, &ur); 4053794Sbostic return (neg ? -ur : ur); 4153442Sbostic } 42