1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. 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 8.1 (Berkeley) 06/04/93"; 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_t 25 __moddi3(a, b) 26 quad_t a, b; 27 { 28 u_quad_t ua, ub, ur; 29 int neg; 30 31 if (a < 0) 32 ua = -(u_quad_t)a, neg = 1; 33 else 34 ua = a, neg = 0; 35 if (b < 0) 36 ub = -(u_quad_t)b, neg ^= 1; 37 else 38 ub = b; 39 (void)__qdivrem(ua, ub, &ur); 40 return (neg ? -ur : ur); 41 } 42