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[] = "@(#)moddi3.c 5.4 (Berkeley) 06/19/92"; 14 #endif /* LIBC_SCCS and not lint */ 15 16 #include "quad.h" 17 18 /* 19 * Return remainder after dividing two signed quads. 20 * 21 * XXX 22 * If -1/2 should produce -1 on this machine, this code is wrong. 23 */ 24 quad 25 __moddi3(quad a, quad b) 26 { 27 u_quad ua, ub, ur; 28 int neg; 29 30 if (a < 0) 31 ua = -(u_quad)a, neg = 1; 32 else 33 ua = a, neg = 0; 34 if (b < 0) 35 ub = -(u_quad)b, neg ^= 1; 36 else 37 ub = b; 38 (void)__qdivrem(ua, ub, &ur); 39 return (neg ? -ur : ur); 40 } 41