11ca671
diff -up gforth-0.7.0/engine/support.c.orig gforth-0.7.0/engine/support.c
11ca671
--- gforth-0.7.0/engine/support.c.orig	2008-11-01 23:06:35.000000000 +0100
11ca671
+++ gforth-0.7.0/engine/support.c	2011-03-21 14:53:52.000000000 +0100
11ca671
@@ -724,16 +724,21 @@ DCell smdiv (DCell num, Cell denom)
11ca671
   DCell res;
11ca671
 #if defined(sdiv_qrnnd)
11ca671
   /* #warning "using sdiv_qrnnd" */
11ca671
-  Cell u1,q,r
11ca671
+  Cell u1,q,r;
11ca671
   UCell u0;
11ca671
   UCell MAYBE_UNUSED lz;
11ca671
   
11ca671
-  vm_d2twoCell(u,u0,u1);
11ca671
-  if (v==0)
11ca671
+  vm_d2twoCell(num,u0,u1);
11ca671
+  if (denom==0)
11ca671
     throw(BALL_DIVZERO);
11ca671
-  if (u1>=v)
11ca671
-    throw(BALL_RESULTRANGE);
11ca671
-  sdiv_qrnnd(q,r,u1,u0,v);
11ca671
+  sdiv_qrnnd(q,r,u1,u0,denom);
11ca671
+  if ((u1^denom)<0) {
11ca671
+    if (q>0)
11ca671
+      throw(BALL_RESULTRANGE);
11ca671
+  } else {
11ca671
+    if (q<0)
11ca671
+      throw(BALL_RESULTRANGE);
11ca671
+  }
11ca671
   vm_twoCell2d(q,r,res);
11ca671
 #else
11ca671
   UDCell ures;