--- gforth/engine/dblsub.c 1997/05/21 20:40:06 1.1 +++ gforth/engine/dblsub.c 2006/10/23 08:45:00 1.7 @@ -1,7 +1,7 @@ /* some routines for double-cell arithmetic only used if BUGGY_LONG_LONG - Copyright (C) 1996 Free Software Foundation, Inc. + Copyright (C) 1996,2000,2003 Free Software Foundation, Inc. * Copyright (C) 1995 Dirk Uwe Zoller * * This library is free software; you can redistribute it and/or @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. This has been adapted from pfe-0.9.14 */ @@ -81,6 +81,10 @@ UDCell umdiv (UDCell u, UCell v) UCell q = 0, h = u.hi, l = u.lo; UDCell res; + if (v==0) + throw(BALL_DIVZERO); + if (h>=v) + throw(BALL_RESULTRANGE); for (;;) { if (c || h >= v) @@ -112,8 +116,14 @@ DCell smdiv (DCell num, Cell denom) /* s if (denomsign < 0) denom = -denom; res = UD2D(umdiv (D2UD(num), denom)); - if ((numsign^denomsign)<0) + if ((numsign^denomsign)<0) { res.lo = -res.lo; + if (((Cell)res.lo) > 0) /* note: == 0 is possible */ + throw(BALL_RESULTRANGE); + } else { + if (((Cell)res.lo) < 0) + throw(BALL_RESULTRANGE); + } if (numsign<0) res.hi = -res.hi; return res; @@ -124,14 +134,18 @@ DCell fmdiv (DCell num, Cell denom) /* f /* I have this technique from Andrew Haley */ DCell res; Cell denomsign=denom; + Cell numsign; if (denom < 0) { denom = -denom; num = dnegate(num); } - if (num.hi < 0) + numsign = num.hi; + if (numsign < 0) num.hi += denom; res = UD2D(umdiv(D2UD(num),denom)); + if ((numsign^((Cell)res.lo)) < 0) + throw(BALL_RESULTRANGE); if (denomsign<0) res.hi = -res.hi; return res;