summaryrefslogtreecommitdiffstats
path: root/lib/libc/quad/moddi3.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/quad/moddi3.c')
-rw-r--r--lib/libc/quad/moddi3.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/libc/quad/moddi3.c b/lib/libc/quad/moddi3.c
index f166feca3b7..0d4517766ab 100644
--- a/lib/libc/quad/moddi3.c
+++ b/lib/libc/quad/moddi3.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: moddi3.c,v 1.3 2003/06/02 20:18:36 millert Exp $";
+static char rcsid[] = "$OpenBSD: moddi3.c,v 1.4 2004/04/27 17:46:46 otto Exp $";
#endif /* LIBC_SCCS and not lint */
#include "quad.h"
@@ -40,24 +40,24 @@ static char rcsid[] = "$OpenBSD: moddi3.c,v 1.3 2003/06/02 20:18:36 millert Exp
/*
* Return remainder after dividing two signed quads.
*
- * XXX
- * If -1/2 should produce -1 on this machine, this code is wrong.
+ * XXX we assume a % b < 0 iff a < 0, but this is actually machine-dependent.
*/
quad_t
__moddi3(a, b)
quad_t a, b;
{
u_quad_t ua, ub, ur;
- int neg;
+ int neg = 0;
+
+ ua = a;
+ ub = b;
if (a < 0)
- ua = -(u_quad_t)a, neg = 1;
- else
- ua = a, neg = 0;
+ ua = -ua, neg ^= 1;
if (b < 0)
- ub = -(u_quad_t)b, neg ^= 1;
- else
- ub = b;
+ ub = -ub;
(void)__qdivrem(ua, ub, &ur);
- return (neg ? -ur : ur);
+ if (neg)
+ ur = -ur;
+ return (ur);
}