added whiteout
[unix-history] / usr / src / lib / libc / quad / divdi3.c
index 0c35574..8531456 100644 (file)
@@ -1,28 +1,39 @@
 /*-
 /*-
- * Copyright (c) 1992 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1992, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
  *
  * %sccs.include.redist.c%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  *
  * %sccs.include.redist.c%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)divdi3.c   5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)divdi3.c   8.1 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #endif /* LIBC_SCCS and not lint */
 
-#include "longlong.h"
+#include "quad.h"
 
 
-long long
-__divdi3 (u, v)
-     long long u, v;
+/*
+ * Divide two signed quads.
+ * ??? if -1/2 should produce -1 on this machine, this code is wrong
+ */
+quad_t
+__divdi3(a, b)
+       quad_t a, b;
 {
 {
-  if (u < 0)
-    if (v < 0)
-      return (unsigned long long) -u / (unsigned long long) -v;
-    else
-      return - ((unsigned long long) -u / (unsigned long long) v);
-  else
-    if (v < 0)
-      return - ((unsigned long long) u / (unsigned long long) -v);
-    else
-      return (unsigned long long) u / (unsigned long long) v;
+       u_quad_t ua, ub, uq;
+       int neg;
+
+       if (a < 0)
+               ua = -(u_quad_t)a, neg = 1;
+       else
+               ua = a, neg = 0;
+       if (b < 0)
+               ub = -(u_quad_t)b, neg ^= 1;
+       else
+               ub = b;
+       uq = __qdivrem(ua, ub, (u_quad_t *)0);
+       return (neg ? -uq : uq);
 }
 }