* Cleaned up memory error signalling.
[bpt/guile.git] / libguile / numbers.c
index 9116735..6d3e808 100644 (file)
@@ -47,7 +47,6 @@
 #include <stdio.h>
 #include <math.h>
 #include "libguile/_scm.h"
-#include "libguile/unif.h"
 #include "libguile/feature.h"
 #include "libguile/ports.h"
 #include "libguile/root.h"
@@ -71,13 +70,26 @@ static SCM scm_divbigint (SCM x, long z, int sgn, int mode);
 #define SCM_SWAP(x,y) do { SCM __t = x; x = y; y = __t; } while (0)
 
 
+#if (SCM_DEBUG_DEPRECATED == 1)  /* not defined in header yet? */
+
+/* SCM_FLOBUFLEN is the maximum number of characters neccessary for the
+ * printed or scm_string representation of an inexact number.
+ */
+#define SCM_FLOBUFLEN (10+2*(sizeof(double)/sizeof(char)*SCM_CHAR_BIT*3+9)/10)
+
+#endif  /* SCM_DEBUG_DEPRECATED == 1 */
+
+
 /* IS_INF tests its floating point number for infiniteness
+   Dirk:FIXME:: This test does not work if x == 0
  */
 #ifndef IS_INF
 #define IS_INF(x) ((x) == (x) / 2)
 #endif
 
+
 /* Return true if X is not infinite and is not a NaN
+   Dirk:FIXME:: Since IS_INF is broken, this test does not work if x == 0
  */
 #ifndef isfinite
 #define isfinite(x) (!IS_INF (x) && (x) == (x))
@@ -158,6 +170,8 @@ scm_abs (SCM x)
     } else {
       return scm_copybig (x, 0);
     }
+  } else if (SCM_REALP (x)) {
+    return scm_make_real (fabs (SCM_REAL_VALUE (x)));
   } else {
     SCM_WTA_DISPATCH_1 (g_abs, x, 1, s_abs);
   }
@@ -245,11 +259,7 @@ scm_remainder (SCM x, SCM y)
       if (yy == 0) {
        scm_num_overflow (s_remainder);
       } else {
-#if (__TURBOC__ == 1)
-       long z = SCM_INUM (x) % (yy < 0 ? -yy : yy);
-#else
        long z = SCM_INUM (x) % yy;
-#endif
        return SCM_MAKINUM (z);
       }
     } else if (SCM_BIGP (y)) {
@@ -290,11 +300,7 @@ scm_modulo (SCM x, SCM y)
       if (yy == 0) {
        scm_num_overflow (s_modulo);
       } else {
-#if (__TURBOC__ == 1)
-       long z = ((yy < 0) ? -xx : xx) % yy;
-#else
        long z = xx % yy;
-#endif
        return SCM_MAKINUM (((yy < 0) ? (z > 0) : (z < 0)) ? z + yy : z);
       }
     } else if (SCM_BIGP (y)) {
@@ -1010,34 +1016,42 @@ SCM_DEFINE (scm_logbit_p, "logbit?", 2, 0, 0,
            "@end example")
 #define FUNC_NAME s_scm_logbit_p
 {
-  SCM_ASSERT(SCM_INUMP(index) && SCM_INUM(index) >= 0, index, SCM_ARG1, FUNC_NAME);
-#ifdef SCM_BIGDIG
-  if SCM_NINUMP(j) {
-    SCM_ASSERT(SCM_BIGP (j), j, SCM_ARG2, FUNC_NAME);
-    if (SCM_NUMDIGS(j) * SCM_BITSPERDIG < SCM_INUM(index)) return SCM_BOOL_F;
-    else if SCM_BIGSIGN(j) {
+  unsigned long int iindex;
+
+  SCM_VALIDATE_INUM_MIN (SCM_ARG1, index, 0);
+  iindex = (unsigned long int) SCM_INUM (index);
+
+  if (SCM_INUMP (j)) {
+    return SCM_BOOL ((1L << iindex) & SCM_INUM (j));
+  } else if (SCM_BIGP (j)) {
+    if (SCM_NUMDIGS (j) * SCM_BITSPERDIG < iindex) {
+      return SCM_BOOL_F;
+    } else if (SCM_BIGSIGN (j)) {
       long num = -1;
       scm_sizet i = 0;
-      SCM_BIGDIG *x = SCM_BDIGITS(j);
-      scm_sizet nx = SCM_INUM(index)/SCM_BITSPERDIG;
-      while (!0) {
+      SCM_BIGDIG * x = SCM_BDIGITS (j);
+      scm_sizet nx = iindex / SCM_BITSPERDIG;
+      while (1) {
        num += x[i];
-       if (nx==i++)
-         return ((1L << (SCM_INUM(index)%SCM_BITSPERDIG)) & num) ? SCM_BOOL_F : SCM_BOOL_T;
-       if (num < 0) num = -1;
-       else num = 0;
+       if (nx == i++) {
+         return SCM_BOOL (((1L << (iindex % SCM_BITSPERDIG)) & num) == 0);
+       } else if (num < 0) {
+         num = -1;
+       } else {
+         num = 0;
+       }
       }
+    } else {
+      return SCM_BOOL (SCM_BDIGITS (j) [iindex / SCM_BITSPERDIG]
+                      & (1L << (iindex % SCM_BITSPERDIG)));
     }
-    else return (SCM_BDIGITS(j)[SCM_INUM(index)/SCM_BITSPERDIG] &
-                (1L << (SCM_INUM(index)%SCM_BITSPERDIG))) ? SCM_BOOL_T : SCM_BOOL_F;
+  } else {
+    SCM_WRONG_TYPE_ARG (SCM_ARG2, j);
   }
-#else
-  SCM_ASSERT(SCM_INUMP(j), j, SCM_ARG2, FUNC_NAME);
-#endif
-  return ((1L << SCM_INUM(index)) & SCM_INUM(j)) ? SCM_BOOL_T : SCM_BOOL_F;
 }
 #undef FUNC_NAME
 
+
 SCM_DEFINE (scm_lognot, "lognot", 1, 0, 0, 
             (SCM n),
            "Returns the integer which is the 2s-complement of the integer argument.\n\n"
@@ -1152,7 +1166,7 @@ SCM_DEFINE (scm_ash, "ash", 2, 0, 0,
 }
 #undef FUNC_NAME
 
-/* GJB:FIXME: do not use SCMs as integers! */
+
 SCM_DEFINE (scm_bit_extract, "bit-extract", 3, 0, 0,
             (SCM n, SCM start, SCM end),
            "Returns the integer composed of the @var{start} (inclusive) through\n"
@@ -1168,24 +1182,25 @@ SCM_DEFINE (scm_bit_extract, "bit-extract", 3, 0, 0,
 #define FUNC_NAME s_scm_bit_extract
 {
   int istart, iend;
-  SCM_VALIDATE_INUM (1,n);
   SCM_VALIDATE_INUM_MIN_COPY (2,start,0,istart);
   SCM_VALIDATE_INUM_MIN_COPY (3, end, 0, iend);
   SCM_ASSERT_RANGE (3, end, (iend >= istart));
-#ifdef SCM_BIGDIG
-  if (SCM_NINUMP (n))
-    return
-      scm_logand (scm_difference (scm_integer_expt (SCM_MAKINUM (2),
-                                                   SCM_MAKINUM (iend - istart)),
-                                 SCM_MAKINUM (1L)),
-                 scm_ash (n, SCM_MAKINUM (-istart)));
-#else
-  SCM_VALIDATE_INUM (1,n);
-#endif
-  return SCM_MAKINUM ((SCM_INUM (n) >> istart) & ((1L << (iend - istart)) - 1));
+
+  if (SCM_INUMP (n)) {
+    return SCM_MAKINUM ((SCM_INUM (n) >> istart) & ((1L << (iend - istart)) - 1));
+  } else if (SCM_BIGP (n)) {
+    SCM num1 = SCM_MAKINUM (1L);
+    SCM num2 = SCM_MAKINUM (2L);
+    SCM bits = SCM_MAKINUM (iend - istart);
+    SCM mask  = scm_difference (scm_integer_expt (num2, bits), num1);
+    return scm_logand (mask, scm_ash (n, SCM_MAKINUM (-istart)));
+  } else {
+    SCM_WRONG_TYPE_ARG (SCM_ARG1, n);
+  }
 }
 #undef FUNC_NAME
 
+
 static const char scm_logtab[] = {
   0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
 };
@@ -1207,30 +1222,35 @@ SCM_DEFINE (scm_logcount, "logcount", 1, 0, 0,
            "@end lisp")
 #define FUNC_NAME s_scm_logcount
 {
-  register unsigned long c = 0;
-  register long nn;
-#ifdef SCM_BIGDIG
-  if (SCM_NINUMP (n))
-    {
-      scm_sizet i;
-      SCM_BIGDIG *ds, d;
-      SCM_VALIDATE_BIGINT (1,n);
-      if (SCM_BIGSIGN (n))
-       return scm_logcount (scm_difference (SCM_MAKINUM (-1L), n));
-      ds = SCM_BDIGITS (n);
-      for (i = SCM_NUMDIGS (n); i--;)
-       for (d = ds[i]; d; d >>= 4)
+  if (SCM_INUMP (n)) {
+    unsigned long int c = 0;
+    long int nn = SCM_INUM (n);
+    if (nn < 0) {
+      nn = -1 - nn;
+    };
+    while (nn) {
+      c += scm_logtab[15 & nn];
+      nn >>= 4;
+    };
+    return SCM_MAKINUM (c);
+  } else if (SCM_BIGP (n)) {
+    if (SCM_BIGSIGN (n)) {
+      return scm_logcount (scm_difference (SCM_MAKINUM (-1L), n));
+    } else {
+      unsigned long int c = 0;
+      scm_sizet i = SCM_NUMDIGS (n);
+      SCM_BIGDIG * ds = SCM_BDIGITS (n);
+      while (i--) {
+       SCM_BIGDIG d;
+       for (d = ds[i]; d; d >>= 4) {
          c += scm_logtab[15 & d];
+       }
+      }
       return SCM_MAKINUM (c);
     }
-#else
-  SCM_VALIDATE_INUM (1,n);
-#endif
-  if ((nn = SCM_INUM (n)) < 0)
-    nn = -1 - nn;
-  for (; nn; nn >>= 4)
-    c += scm_logtab[15 & nn];
-  return SCM_MAKINUM (c);
+  } else {
+    SCM_WRONG_TYPE_ARG (SCM_ARG1, n);
+  }
 }
 #undef FUNC_NAME
 
@@ -1253,36 +1273,38 @@ SCM_DEFINE (scm_integer_length, "integer-length", 1, 0, 0,
            "@end lisp")
 #define FUNC_NAME s_scm_integer_length
 {
-  register unsigned long c = 0;
-  register long nn;
-  unsigned int l = 4;
-#ifdef SCM_BIGDIG
-  if (SCM_NINUMP (n))
-    {
-      SCM_BIGDIG *ds, d;
-      SCM_VALIDATE_BIGINT (1,n);
-      if (SCM_BIGSIGN (n))
-       return scm_integer_length (scm_difference (SCM_MAKINUM (-1L), n));
-      ds = SCM_BDIGITS (n);
-      d = ds[c = SCM_NUMDIGS (n) - 1];
-      for (c *= SCM_BITSPERDIG; d; d >>= 4)
-       {
-         c += 4;
-         l = scm_ilentab[15 & d];
-       }
-      return SCM_MAKINUM (c - 4 + l);
-    }
-#else
-  SCM_VALIDATE_INUM (1,n);
-#endif
-  if ((nn = SCM_INUM (n)) < 0)
-    nn = -1 - nn;
-  for (; nn; nn >>= 4)
-    {
+  if (SCM_INUMP (n)) {
+    unsigned long int c = 0;
+    unsigned int l = 4;
+    long int nn = SCM_INUM (n);
+    if (nn < 0) {
+      nn = -1 - nn;
+    };
+    while (nn) {
       c += 4;
-      l = scm_ilentab[15 & nn];
+      l = scm_ilentab [15 & nn];
+      nn >>= 4;
+    };
+    return SCM_MAKINUM (c - 4 + l);
+  } else if (SCM_BIGP (n)) {
+    if (SCM_BIGSIGN (n)) {
+      return scm_integer_length (scm_difference (SCM_MAKINUM (-1L), n));
+    } else {
+      unsigned long int digs = SCM_NUMDIGS (n) - 1;
+      unsigned long int c = digs * SCM_BITSPERDIG;
+      unsigned int l = 4;
+      SCM_BIGDIG * ds = SCM_BDIGITS (n);
+      SCM_BIGDIG d = ds [digs];
+      while (d) {
+       c += 4;
+       l = scm_ilentab [15 & d];
+       d >>= 4;
+      };
+      return SCM_MAKINUM (c - 4 + l);
     }
-  return SCM_MAKINUM (c - 4 + l);
+  } else {
+    SCM_WRONG_TYPE_ARG (SCM_ARG1, n);
+  }
 }
 #undef FUNC_NAME
 
@@ -1297,7 +1319,7 @@ scm_mkbig (scm_sizet nlen, int sign)
   /* Cast to long int to avoid signed/unsigned comparison warnings.  */
   if ((( ((long int) nlen) << SCM_BIGSIZEFIELD) >> SCM_BIGSIZEFIELD)
       != (long int) nlen)
-    scm_wta (SCM_MAKINUM (nlen), (char *) SCM_NALLOC, s_bignum);
+    scm_memory_error (s_bignum);
   
   SCM_NEWCELL (v);
   SCM_DEFER_INTS;
@@ -1321,7 +1343,7 @@ scm_big2inum (SCM b, scm_sizet l)
       if (SCM_POSFIXABLE (num))
        return SCM_MAKINUM (num);
     }
-  else if (SCM_UNEGFIXABLE (num))
+  else if (num <= -SCM_MOST_NEGATIVE_FIXNUM)
     return SCM_MAKINUM (-num);
   return b;
 }
@@ -1334,7 +1356,7 @@ scm_adjbig (SCM b, scm_sizet nlen)
 {
   scm_sizet nsiz = nlen;
   if (((nsiz << SCM_BIGSIZEFIELD) >> SCM_BIGSIZEFIELD) != nlen)
-    scm_wta (scm_ulong2num (nsiz), (char *) SCM_NALLOC, s_adjbig);
+    scm_memory_error (s_adjbig);
 
   SCM_DEFER_INTS;
   {
@@ -1442,7 +1464,7 @@ scm_long_long2big (long_long n)
     }
   return ans;
 }
-#endif
+#endif /* HAVE_LONG_LONGS */
 
 
 SCM
@@ -1689,16 +1711,8 @@ scm_mulbig (SCM_BIGDIG *x, scm_sizet nx, SCM_BIGDIG *y, scm_sizet ny, int sgn)
 }
 
 
-/* Sun's compiler complains about the fact that this function has an
-   ANSI prototype in numbers.h, but a K&R declaration here, and the
-   two specify different promotions for the third argument.  I'm going
-   to turn this into an ANSI declaration, and see if anyone complains
-   about it not being K&R.  */
-
 unsigned int
-scm_divbigdig (SCM_BIGDIG * ds,
-              scm_sizet h,
-              SCM_BIGDIG div)
+scm_divbigdig (SCM_BIGDIG * ds, scm_sizet h, SCM_BIGDIG div)
 {
   register unsigned long t2 = 0;
   while (h--)
@@ -2200,39 +2214,33 @@ big2str (SCM b, unsigned int radix)
 
 
 SCM_DEFINE (scm_number_to_string, "number->string", 1, 1, 0,
-            (SCM x, SCM radix),
-           "")
+            (SCM n, SCM radix),
+           "Return a string holding the external representation of the\n"
+           "number N in the given RADIX.  If N is inexact, a radix of 10\n"
+           "will be used.")
 #define FUNC_NAME s_scm_number_to_string
 {
   int base;
-  SCM_VALIDATE_INUM_MIN_DEF_COPY (2,radix,2,10,base);
-  if (SCM_NINUMP (x))
-    {
-      char num_buf[SCM_FLOBUFLEN];
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (x), badx);
-      if (SCM_BIGP (x))
-       return big2str (x, (unsigned int) base);
-#ifndef SCM_RECKLESS
-      if (!SCM_SLOPPY_INEXACTP (x))
-       {
-       badx:
-         SCM_WTA (1, x);
-       }
-#endif
-#else
-      SCM_ASSERT (SCM_SLOPPY_INEXACTP (x),
-                 x, SCM_ARG1, s_number_to_string);
-#endif
-      return scm_makfromstr (num_buf, iflo2str (x, num_buf), 0);
-    }
-  {
-    char num_buf[SCM_INTBUFLEN];
-    return scm_makfromstr (num_buf,
-                          scm_iint2str (SCM_INUM (x),
-                                        base,
-                                        num_buf),
-                          0);
+
+  if (SCM_UNBNDP (radix)) {
+    base = 10;
+  } else {
+    SCM_VALIDATE_INUM (2, radix);
+    base = SCM_INUM (radix);
+    SCM_ASSERT_RANGE (2, radix, base >= 2);
+  }
+
+  if (SCM_INUMP (n)) {
+    char num_buf [SCM_INTBUFLEN];
+    scm_sizet length = scm_iint2str (SCM_INUM (n), base, num_buf);
+    return scm_makfromstr (num_buf, length, 0);
+  } else if (SCM_BIGP (n)) {
+    return big2str (n, (unsigned int) base);
+  } else if (SCM_INEXACTP (n)) {
+    char num_buf [SCM_FLOBUFLEN];
+    return scm_makfromstr (num_buf, iflo2str (n, num_buf), 0);
+  } else {
+    SCM_WRONG_TYPE_ARG (1, n);
   }
 }
 #undef FUNC_NAME
@@ -2689,7 +2697,7 @@ scm_istr2flo (char *str, long len, long radix)
          return SCM_BOOL_F;    /* not `real' */
        if (SCM_SLOPPY_COMPLEXP (second))
          return SCM_BOOL_F;    /* not `real' */
-       tmp = SCM_REALPART (second);
+       tmp = SCM_REAL_VALUE (second);
        return scm_make_complex (res * cos (tmp), res * sin (tmp));
       }
     default:
@@ -2708,7 +2716,7 @@ scm_istr2flo (char *str, long len, long radix)
     return SCM_BOOL_F;         /* not `ureal' */
   if (SCM_SLOPPY_COMPLEXP (second))
     return SCM_BOOL_F;         /* not `ureal' */
-  tmp = SCM_REALPART (second);
+  tmp = SCM_REAL_VALUE (second);
   if (tmp < 0.0)
     return SCM_BOOL_F;         /* not `ureal' */
   return scm_make_complex (res, (lead_sgn * tmp));
@@ -2786,38 +2794,55 @@ scm_istring2number (char *str, long len, long radix)
 
 
 SCM_DEFINE (scm_string_to_number, "string->number", 1, 1, 0,
-            (SCM str, SCM radix),
-           "")
+            (SCM string, SCM radix),
+           "Returns a number of the maximally precise representation\n"
+           "expressed by the given STRING. RADIX must be an exact integer,\n"
+           "either 2, 8, 10, or 16. If supplied, RADIX is a default radix\n"
+           "that may be overridden by an explicit radix prefix in STRING\n"
+           "(e.g. \"#o177\"). If RADIX is not supplied, then the default\n"
+           "radix is 10. If string is not a syntactically valid notation\n"
+           "for a number, then `string->number' returns #f.  (r5rs)") 
 #define FUNC_NAME s_scm_string_to_number
 {
   SCM answer;
   int base;
-  SCM_VALIDATE_ROSTRING (1,str);
+  SCM_VALIDATE_ROSTRING (1,string);
   SCM_VALIDATE_INUM_MIN_DEF_COPY (2,radix,2,10,base);
-  answer = scm_istring2number (SCM_ROCHARS (str),
-                              SCM_ROLENGTH (str),
+  answer = scm_istring2number (SCM_ROCHARS (string),
+                              SCM_ROLENGTH (string),
                                base);
-  return scm_return_first (answer, str);
+  return scm_return_first (answer, string);
 }
 #undef FUNC_NAME
 /*** END strs->nums ***/
 
+
 SCM
 scm_make_real (double x)
 {
   SCM z;
-  SCM_NEWREAL (z, x);
+  SCM_NEWCELL2 (z);
+  SCM_SET_CELL_TYPE (z, scm_tc16_real);
+  SCM_REAL_VALUE (z) = x;
   return z;
 }
 
+
 SCM
 scm_make_complex (double x, double y)
 {
-  SCM z;
-  SCM_NEWCOMPLEX (z, x, y);
-  return z;
+  if (y == 0.0) {
+    return scm_make_real (x);
+  } else {
+    SCM z;
+    SCM_NEWSMOB (z, scm_tc16_complex, scm_must_malloc (2L * sizeof (double), "complex"));
+    SCM_COMPLEX_REAL (z) = x;
+    SCM_COMPLEX_IMAG (z) = y;
+    return z;
+  }
 }
 
+
 SCM
 scm_bigequal (SCM x, SCM y)
 {
@@ -2847,46 +2872,45 @@ SCM_REGISTER_PROC (s_number_p, "number?", 1, 0, 0, scm_number_p);
 
 SCM_DEFINE (scm_number_p, "complex?", 1, 0, 0, 
             (SCM x),
-           "")
+           "Return #t if X is a complex number, #f else.  Note that the\n"
+           "sets of real, rational and integer values form subsets of the\n"
+           "set of complex numbers, i. e. the predicate will also be\n"
+           "fulfilled if X is a real, rational or integer number.")
 #define FUNC_NAME s_scm_number_p
 {
-  if (SCM_INUMP (x))
-    return SCM_BOOL_T;
-  if (SCM_NUMP (x))
-    return SCM_BOOL_T;
-  return SCM_BOOL_F;
+  return SCM_BOOL (SCM_NUMBERP (x));
 }
 #undef FUNC_NAME
 
 
-
 SCM_REGISTER_PROC (s_real_p, "real?", 1, 0, 0, scm_real_p);
 
-
 SCM_DEFINE (scm_real_p, "rational?", 1, 0, 0, 
             (SCM x),
-           "")
+           "Return #t if X is a rational number, #f else.  Note that the\n"
+           "set of integer values forms a subset of the set of rational\n"
+           "numbers, i. e. the predicate will also be fulfilled if X is an\n"
+           "integer number.")
 #define FUNC_NAME s_scm_real_p
 {
-  if (SCM_INUMP (x))
+  if (SCM_INUMP (x)) {
     return SCM_BOOL_T;
-  if (SCM_IMP (x))
+  } else if (SCM_IMP (x)) {
     return SCM_BOOL_F;
-  if (SCM_SLOPPY_REALP (x))
+  } else if (SCM_SLOPPY_REALP (x)) {
     return SCM_BOOL_T;
-#ifdef SCM_BIGDIG
-  if (SCM_BIGP (x))
+  } else if (SCM_BIGP (x)) {
     return SCM_BOOL_T;
-#endif
-  return SCM_BOOL_F;
+  } else {
+    return SCM_BOOL_F;
+  }
 }
 #undef FUNC_NAME
 
 
-
 SCM_DEFINE (scm_integer_p, "integer?", 1, 0, 0, 
             (SCM x),
-           "")
+           "Return #t if X is an integer number, #f else.")
 #define FUNC_NAME s_scm_integer_p
 {
   double r;
@@ -2894,15 +2918,13 @@ SCM_DEFINE (scm_integer_p, "integer?", 1, 0, 0,
     return SCM_BOOL_T;
   if (SCM_IMP (x))
     return SCM_BOOL_F;
-#ifdef SCM_BIGDIG
   if (SCM_BIGP (x))
     return SCM_BOOL_T;
-#endif
   if (!SCM_SLOPPY_INEXACTP (x))
     return SCM_BOOL_F;
   if (SCM_SLOPPY_COMPLEXP (x))
     return SCM_BOOL_F;
-  r = SCM_REALPART (x);
+  r = SCM_REAL_VALUE (x);
   if (r == floor (r))
     return SCM_BOOL_T;
   return SCM_BOOL_F;
@@ -2910,10 +2932,9 @@ SCM_DEFINE (scm_integer_p, "integer?", 1, 0, 0,
 #undef FUNC_NAME
 
 
-
 SCM_DEFINE (scm_inexact_p, "inexact?", 1, 0, 0, 
             (SCM x),
-           "")
+           "Return #t if X is an inexact number, #f else.")
 #define FUNC_NAME s_scm_inexact_p
 {
   return SCM_BOOL (SCM_INEXACTP (x));
@@ -3034,7 +3055,8 @@ scm_less_p (SCM x, SCM y)
 
 SCM_DEFINE1 (scm_gr_p, ">", scm_tc7_rpsubr,
              (SCM x, SCM y),
-            "")
+            "Return #t if the list of parameters is monotonically\n"
+            "increasing.")
 #define FUNC_NAME s_scm_gr_p
 {
   return scm_less_p (y, x);
@@ -3044,7 +3066,8 @@ SCM_DEFINE1 (scm_gr_p, ">", scm_tc7_rpsubr,
 
 SCM_DEFINE1 (scm_leq_p, "<=", scm_tc7_rpsubr,
              (SCM x, SCM y),
-            "")
+            "Return #t if the list of parameters is monotonically\n"
+            "non-decreasing.")
 #define FUNC_NAME s_scm_leq_p
 {
   return SCM_BOOL_NOT (scm_less_p (y, x));
@@ -3054,7 +3077,8 @@ SCM_DEFINE1 (scm_leq_p, "<=", scm_tc7_rpsubr,
 
 SCM_DEFINE1 (scm_geq_p, ">=", scm_tc7_rpsubr,
              (SCM x, SCM y),
-            "")
+            "Return #t if the list of parameters is monotonically\n"
+            "non-increasing.")
 #define FUNC_NAME s_scm_geq_p
 {
   return SCM_BOOL_NOT (scm_less_p (x, y));
@@ -3067,82 +3091,52 @@ SCM_GPROC (s_zero_p, "zero?", 1, 0, 0, scm_zero_p, g_zero_p);
 SCM
 scm_zero_p (SCM z)
 {
-  if (SCM_NINUMP (z))
-    {
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (z), badz);
-      if (SCM_BIGP (z))
-       return SCM_BOOL_F;
-      if (!SCM_SLOPPY_INEXACTP (z))
-       {
-       badz:
-         SCM_WTA_DISPATCH_1 (g_zero_p, z, SCM_ARG1, s_zero_p);
-       }
-#else
-      SCM_GASSERT1 (SCM_SLOPPY_INEXACTP (z),
-                   g_zero_p, z, SCM_ARG1, s_zero_p);
-#endif
-      if (SCM_SLOPPY_REALP (z))
-       return SCM_BOOL (SCM_REAL_VALUE (z) == 0.0);
-      else
-       return SCM_BOOL (SCM_COMPLEX_REAL (z) == 0.0
-                        && SCM_COMPLEX_IMAG (z) == 0.0);
-    }
-  return SCM_BOOL (SCM_EQ_P (z, SCM_INUM0));
+  if (SCM_INUMP (z)) {
+    return SCM_BOOL (SCM_EQ_P (z, SCM_INUM0));
+  } else if (SCM_BIGP (z)) {
+    return SCM_BOOL_F;
+  } else if (SCM_REALP (z)) {
+    return SCM_BOOL (SCM_REAL_VALUE (z) == 0.0);
+  } else if (SCM_COMPLEXP (z)) {
+    return SCM_BOOL (SCM_COMPLEX_REAL (z) == 0.0
+                    && SCM_COMPLEX_IMAG (z) == 0.0);
+  } else {
+    SCM_WTA_DISPATCH_1 (g_zero_p, z, SCM_ARG1, s_zero_p);
+  }
 }
 
 
-
 SCM_GPROC (s_positive_p, "positive?", 1, 0, 0, scm_positive_p, g_positive_p);
 
 SCM
 scm_positive_p (SCM x)
 {
-  if (SCM_NINUMP (x))
-    {
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (x), badx);
-      if (SCM_BIGP (x))
-       return SCM_BOOL (!SCM_BIGSIGN (x));
-      if (!SCM_SLOPPY_REALP (x))
-       {
-       badx:
-         SCM_WTA_DISPATCH_1 (g_positive_p, x, SCM_ARG1, s_positive_p);
-       }
-#else
-      SCM_GASSERT1 (SCM_SLOPPY_REALP (x),
-                   g_positive_p, x, SCM_ARG1, s_positive_p);
-#endif
-      return SCM_BOOL(SCM_REALPART (x) > 0.0);
-    }
-  return SCM_BOOL(SCM_INUM(x) > 0);
+  if (SCM_INUMP (x)) {
+    return SCM_BOOL (SCM_INUM (x) > 0);
+  } else if (SCM_BIGP (x)) {
+    return SCM_BOOL (!SCM_BIGSIGN (x));
+  } else if (SCM_REALP (x)) {
+    return SCM_BOOL(SCM_REAL_VALUE (x) > 0.0);
+  } else {
+    SCM_WTA_DISPATCH_1 (g_positive_p, x, SCM_ARG1, s_positive_p);
+  }
 }
 
 
-
 SCM_GPROC (s_negative_p, "negative?", 1, 0, 0, scm_negative_p, g_negative_p);
 
 SCM
 scm_negative_p (SCM x)
 {
-  if (SCM_NINUMP (x))
-    {
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (x), badx);
-      if (SCM_BIGP (x))
-       return SCM_BOOL (SCM_BIGSIGN (x));
-      if (!(SCM_SLOPPY_REALP (x)))
-       {
-       badx:
-         SCM_WTA_DISPATCH_1 (g_negative_p, x, SCM_ARG1, s_negative_p);
-       }
-#else
-      SCM_GASSERT1 (SCM_SLOPPY_REALP (x),
-                   g_negative_p, x, SCM_ARG1, s_negative_p);
-#endif
-      return SCM_BOOL(SCM_REALPART (x) < 0.0);
-    }
-  return SCM_BOOL(SCM_INUM(x) < 0);
+  if (SCM_INUMP (x)) {
+    return SCM_BOOL (SCM_INUM (x) < 0);
+  } else if (SCM_BIGP (x)) {
+    return SCM_BOOL (SCM_BIGSIGN (x));
+  } else if (SCM_REALP (x)) {
+    return SCM_BOOL(SCM_REAL_VALUE (x) < 0.0);
+  } else {
+    SCM_WTA_DISPATCH_1 (g_negative_p, x, SCM_ARG1, s_negative_p);
+  }
 }
 
 
@@ -3262,294 +3256,232 @@ scm_min (SCM x, SCM y)
 
 SCM_GPROC1 (s_sum, "+", scm_tc7_asubr, scm_sum, g_sum);
 
-/*
-  This is sick, sick, sick code.
-
- */
 SCM
 scm_sum (SCM x, SCM y)
 {
-  if (SCM_UNBNDP (y))
-    {
-      if (SCM_UNBNDP (x))
-       return SCM_INUM0;
-      SCM_GASSERT1 (SCM_NUMBERP (x), g_sum, x, SCM_ARG1, s_sum);
+  if (SCM_UNBNDP (y)) {
+    if (SCM_UNBNDP (x)) {
+      return SCM_INUM0;
+    } else if (SCM_NUMBERP (x)) {
       return x;
+    } else {
+      SCM_WTA_DISPATCH_1 (g_sum, x, SCM_ARG1, s_sum);
     }
-  if (SCM_NINUMP (x))
-    {
-# ifdef SCM_BIGDIG
-      if (!SCM_NIMP (x))
-       {
-       badx2:
-         SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARG1, s_sum);
-       }
-      if (SCM_BIGP (x))
-       {
-         if (SCM_INUMP (y))
-           {
-             SCM_SWAP(x,y);
-             goto intbig;
-           }
-         SCM_ASRTGO (SCM_NIMP (y), bady);
-         if (SCM_BIGP (y))
-           {
-             if (SCM_NUMDIGS (x) > SCM_NUMDIGS (y))
-               {
-                 SCM_SWAP(x,y);
-               }
-             return scm_addbig (SCM_BDIGITS (x), SCM_NUMDIGS (x),
-                                SCM_BIGSIGN (x),
-                                y, 0);
-           }
-         SCM_ASRTGO (SCM_SLOPPY_INEXACTP (y), bady);
-       bigreal:
-         if (SCM_SLOPPY_REALP (y))
-           return scm_make_real (scm_big2dbl (x) + SCM_REAL_VALUE (y));
-         else
-           return scm_make_complex (scm_big2dbl (x) + SCM_COMPLEX_REAL (y),
-                                    SCM_COMPLEX_IMAG (y));
-       }
-# endif /* SCM_BIGDIG */
-      SCM_ASRTGO (SCM_SLOPPY_INEXACTP (x), badx2);
+  }
 
-      if (SCM_INUMP (y))
-       {
-         SCM_SWAP(x,y);
-         goto intreal;
-       }
-# ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (y), bady);
-      if (SCM_BIGP (y))
-       {
-         SCM_SWAP(x,y);
-         goto bigreal;
-       }
-      else if (!SCM_SLOPPY_INEXACTP (y))
-       {
-       bady:
-         SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARGn, s_sum);
-       }
-# else  /* SCM_BIGDIG */
-      if (!SCM_SLOPPY_INEXACTP (y))
-       {
-       bady:
-         SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARGn, s_sum);
-       }
-# endif /* SCM_BIGDIG */
+  if (SCM_INUMP (x)) {
+    long int xx = SCM_INUM (x);
+    if (SCM_INUMP (y)) {
+      long int yy = SCM_INUM (y);
+      long int z = xx + yy;
+      if (SCM_FIXABLE (z)) {
+       return SCM_MAKINUM (z);
+      } else {
+#ifdef SCM_BIGDIG
+       return scm_long2big (z);
+#else  /* SCM_BIGDIG */
+       return scm_make_real ((double) z);
+#endif /* SCM_BIGDIG */ 
+      }
+    } else if (SCM_BIGP (y)) {
+    intbig:
       {
-       double i = 0.0;
-       if (SCM_SLOPPY_COMPLEXP (x))
-         i = SCM_COMPLEX_IMAG (x);
-       if (SCM_SLOPPY_COMPLEXP (y))
-         i += SCM_COMPLEX_IMAG (y);
-       return scm_make_complex (SCM_REALPART (x) + SCM_REALPART (y), i);
+       long int xx = SCM_INUM (x);
+#ifndef SCM_DIGSTOOBIG
+       long z = scm_pseudolong (xx);
+       return scm_addbig ((SCM_BIGDIG *) & z, SCM_DIGSPERLONG,
+                          (xx < 0) ? SCM_BIGSIGNFLAG : 0, y, 0);
+#else  /* SCM_DIGSTOOBIG */
+       SCM_BIGDIG zdigs [SCM_DIGSPERLONG];
+       scm_longdigs (xx, zdigs);
+       return scm_addbig (zdigs, SCM_DIGSPERLONG, 
+                          (xx < 0) ? SCM_BIGSIGNFLAG : 0, y, 0);
+#endif /* SCM_DIGSTOOBIG */
       }
+    } else if (SCM_REALP (y)) {
+      return scm_make_real (xx + SCM_REAL_VALUE (y));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (xx + SCM_COMPLEX_REAL (y),
+                              SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARGn, s_sum);
     }
-  if (SCM_NINUMP (y))
-    {
-# ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (y), bady);
-      if (SCM_BIGP (y))
-       {
-       intbig:
-         {
-           long i = SCM_INUM (x);
-#  ifndef SCM_DIGSTOOBIG
-           long z = scm_pseudolong (i);
-           return scm_addbig ((SCM_BIGDIG *) & z,
-                              SCM_DIGSPERLONG,
-                              (i < 0) ? SCM_BIGSIGNFLAG : 0,
-                              y, 0);
-#  else  /* SCM_DIGSTOOBIG */
-           SCM_BIGDIG zdigs[SCM_DIGSPERLONG];
-           scm_longdigs (i, zdigs);
-           return scm_addbig (zdigs, SCM_DIGSPERLONG, (i < 0) ? SCM_BIGSIGNFLAG : 0,
-                              y, 0);
-#  endif /* SCM_DIGSTOOBIG */
-         }
-       }
-# endif /* SCM_BIGDIG */
-      SCM_ASRTGO (SCM_SLOPPY_INEXACTP (y), bady);
-    intreal:
-      if (SCM_REALP (y))
-       return scm_make_real (SCM_INUM (x) + SCM_REAL_VALUE (y));
-      else
-       return scm_make_complex (SCM_INUM (x) + SCM_COMPLEX_REAL (y),
-                                SCM_COMPLEX_IMAG (y));
+  } else if (SCM_BIGP (x)) {
+    if (SCM_INUMP (y)) {
+      SCM_SWAP (x, y);
+      goto intbig;
+    } else if (SCM_BIGP (y)) {
+      if (SCM_NUMDIGS (x) > SCM_NUMDIGS (y)) {
+       SCM_SWAP (x, y);
+      }
+      return scm_addbig (SCM_BDIGITS (x), SCM_NUMDIGS (x), 
+                        SCM_BIGSIGN (x), y, 0);
+    } else if (SCM_REALP (y)) {
+      return scm_make_real (scm_big2dbl (x) + SCM_REAL_VALUE (y));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (scm_big2dbl (x) + SCM_COMPLEX_REAL (y),
+                              SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARGn, s_sum);
     }
-  { /* scope */
-    long int i = SCM_INUM (x) + SCM_INUM (y);
-    if (SCM_FIXABLE (i))
-      return SCM_MAKINUM (i);
-#ifdef SCM_BIGDIG
-    return scm_long2big (i);
-#else  /* SCM_BIGDIG */
-    return scm_make_real ((double) i);
-#endif /* SCM_BIGDIG */ 
-  } /* end scope */
+  } else if (SCM_REALP (x)) {
+    if (SCM_INUMP (y)) {
+      return scm_make_real (SCM_REAL_VALUE (x) + SCM_INUM (y));
+    } else if (SCM_BIGP (y)) {
+      return scm_make_real (SCM_REAL_VALUE (x) + scm_big2dbl (y));
+    } else if (SCM_REALP (y)) {
+      return scm_make_real (SCM_REAL_VALUE (x) + SCM_REAL_VALUE (y));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (SCM_REAL_VALUE (x) + SCM_COMPLEX_REAL (y),
+                              SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARGn, s_sum);
+    }
+  } else if (SCM_COMPLEXP (x)) {
+    if (SCM_INUMP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) + SCM_INUM (y),
+                              SCM_COMPLEX_IMAG (x));
+    } else if (SCM_BIGP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) + scm_big2dbl (y),
+                              SCM_COMPLEX_IMAG (x));
+    } else if (SCM_REALP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) + SCM_REAL_VALUE (y),
+                              SCM_COMPLEX_IMAG (x));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) + SCM_COMPLEX_REAL (y),
+                              SCM_COMPLEX_IMAG (x) + SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARGn, s_sum);
+    }
+  } else {
+    SCM_WTA_DISPATCH_2 (g_sum, x, y, SCM_ARG1, s_sum);
+  }
 }
 
 
-
-
 SCM_GPROC1 (s_difference, "-", scm_tc7_asubr, scm_difference, g_difference);
 
-/*
-  HWN:FIXME:: This is sick,sick, sick code. Rewrite me.
-*/
 SCM
 scm_difference (SCM x, SCM y)
 {
-  long int cx = 0;
-  if (SCM_NINUMP (x))
-    {
-      if (!SCM_NIMP (x))
-       {
-         if (SCM_UNBNDP (y))
-           {
-             SCM_GASSERT0 (!SCM_UNBNDP (x), g_difference,
-                           scm_makfrom0str (s_difference), SCM_WNA, 0);
-           badx:
-             SCM_WTA_DISPATCH_1 (g_difference, x, SCM_ARG1, s_difference);
-           }
-         else
-           {
-           badx2:
-             SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARG1, s_difference);
-           }
-       }
-      if (SCM_UNBNDP (y))
-       {
+  if (SCM_UNBNDP (y)) {
+    if (SCM_INUMP (x)) {
+      long xx = -SCM_INUM (x);
+      if (SCM_FIXABLE (xx)) {
+       return SCM_MAKINUM (xx);
+      } else {
 #ifdef SCM_BIGDIG
-         if (SCM_BIGP (x))
-           {
-             x = scm_copybig (x, !SCM_BIGSIGN (x));
-             return (SCM_NUMDIGS (x) * SCM_BITSPERDIG / SCM_CHAR_BIT
-                     <= sizeof (SCM)
-                     ? scm_big2inum (x, SCM_NUMDIGS (x))
-                     : x);
-           }
+       return scm_long2big (xx);
+#else
+       return scm_make_real ((double) xx);
 #endif
-         SCM_ASRTGO (SCM_SLOPPY_INEXACTP (x), badx);
-         if (SCM_SLOPPY_REALP (x))
-           return scm_make_real (- SCM_REAL_VALUE (x));
-         else
-           return scm_make_complex (- SCM_COMPLEX_REAL (x),
-                                    - SCM_COMPLEX_IMAG (x));
-       }
-      if (SCM_INUMP (y))
-       return scm_sum (x, SCM_MAKINUM (- SCM_INUM (y)));
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (y), bady);
-      if (SCM_BIGP (x))
-       {
-         if (SCM_BIGP (y))
-           return ((SCM_NUMDIGS (x) < SCM_NUMDIGS (y))
-                   ? scm_addbig (SCM_BDIGITS (x), SCM_NUMDIGS (x),
-                                 SCM_BIGSIGN (x),
-                                 y, SCM_BIGSIGNFLAG)
-                   : scm_addbig (SCM_BDIGITS (y), SCM_NUMDIGS (y),
-                                 SCM_BIGSIGN (y) ^ SCM_BIGSIGNFLAG,
-                                 x, 0));
-         SCM_ASRTGO (SCM_SLOPPY_INEXACTP (y), bady);
-         if (SCM_REALP (y))
-           return scm_make_real (scm_big2dbl (x) - SCM_REAL_VALUE (y));
-         else
-           return scm_make_complex (scm_big2dbl (x) - SCM_COMPLEX_REAL (y),
-                                    - SCM_COMPLEX_IMAG (y));
-       }
-      SCM_ASRTGO (SCM_SLOPPY_INEXACTP (x), badx2);
-      if (SCM_BIGP (y))
-       {
-         if (SCM_REALP (x))
-           return scm_make_real (SCM_REAL_VALUE (x) - scm_big2dbl (y));
-         else
-           return scm_make_complex (SCM_COMPLEX_REAL (x) - scm_big2dbl (y),
-                                    SCM_COMPLEX_IMAG (x));
-       }
-      SCM_ASRTGO (SCM_SLOPPY_INEXACTP (y), bady);
-#else
-      SCM_ASRTGO (SCM_SLOPPY_INEXACTP (x), badx2);
-      SCM_ASRTGO (SCM_SLOPPY_INEXACTP (y), bady);
-#endif
-      {
-       SCM z;
-       if (SCM_SLOPPY_COMPLEXP (x))
-         {
-           if (SCM_SLOPPY_COMPLEXP (y))
-             SCM_NEWCOMPLEX (z,
-                             SCM_COMPLEX_REAL (x) - SCM_COMPLEX_REAL (y),
-                             SCM_COMPLEX_IMAG (x) - SCM_COMPLEX_IMAG (y));
-           else
-             SCM_NEWCOMPLEX (z,
-                             SCM_COMPLEX_REAL (x) - SCM_REAL_VALUE (y),
-                             SCM_COMPLEX_IMAG (x));
-         }
-       else
-         {
-           if (SCM_SLOPPY_COMPLEXP (y))
-             SCM_NEWCOMPLEX (z,
-                             SCM_REAL_VALUE (x) - SCM_COMPLEX_REAL (y),
-                             - SCM_COMPLEX_IMAG (y));
-           else
-             SCM_NEWREAL (z, SCM_REAL_VALUE (x) - SCM_REAL_VALUE (y));
-         }
-       return z;
       }
+    } else if (SCM_BIGP (x)) {
+      SCM z = scm_copybig (x, !SCM_BIGSIGN (x));
+      unsigned int digs = SCM_NUMDIGS (z);
+      unsigned int size = digs * SCM_BITSPERDIG / SCM_CHAR_BIT;
+      return size <= sizeof (SCM) ? scm_big2inum (z, digs) : z;
+    } else if (SCM_REALP (x)) {
+      return scm_make_real (-SCM_REAL_VALUE (x));
+    } else if (SCM_COMPLEXP (x)) {
+      return scm_make_complex (-SCM_COMPLEX_REAL (x), -SCM_COMPLEX_IMAG (x));
+    } else {
+      SCM_WTA_DISPATCH_1 (g_difference, x, SCM_ARG1, s_difference);
     }
-  if (SCM_UNBNDP (y))
-    {
-      cx = -SCM_INUM (x);
-      goto checkx;
-    }
-  if (SCM_NINUMP (y))
-    {
+  }
+
+  if (SCM_INUMP (x)) {
+    long int xx = SCM_INUM (x);
+    if (SCM_INUMP (y)) {
+      long int yy = SCM_INUM (y);
+      long int z = xx - yy;
+      if (SCM_FIXABLE (z)) {
+       return SCM_MAKINUM (z);
+      } else {
 #ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (y), bady);
-      if (SCM_BIGP (y))
-       {
-         long i = SCM_INUM (x);
-#ifndef SCM_DIGSTOOBIG
-         long z = scm_pseudolong (i);
-         return scm_addbig ((SCM_BIGDIG *) & z, SCM_DIGSPERLONG,
-                            (i < 0) ? SCM_BIGSIGNFLAG : 0,
-                            y, SCM_BIGSIGNFLAG);
+       return scm_long2big (z);
 #else
-         SCM_BIGDIG zdigs[SCM_DIGSPERLONG];
-         scm_longdigs (i, zdigs);
-         return scm_addbig (zdigs, SCM_DIGSPERLONG, (i < 0) ? SCM_BIGSIGNFLAG : 0,
-                            y, SCM_BIGSIGNFLAG);
+       return scm_make_real ((double) z);
 #endif
-       }
-      if (!SCM_SLOPPY_INEXACTP (y))
-       {
-       bady:
-         SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARGn, s_difference);
-       }
+      }
+    } else if (SCM_BIGP (y)) {
+#ifndef SCM_DIGSTOOBIG
+      long z = scm_pseudolong (xx);
+      return scm_addbig ((SCM_BIGDIG *) & z, SCM_DIGSPERLONG,
+                        (xx < 0) ? SCM_BIGSIGNFLAG : 0, y, SCM_BIGSIGNFLAG);
 #else
-      if (!SCM_SLOPPY_INEXACTP (y))
-       {
-       bady:
-         SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARGn, s_difference);
-       }
+      SCM_BIGDIG zdigs [SCM_DIGSPERLONG];
+      scm_longdigs (xx, zdigs);
+      return scm_addbig (zdigs, SCM_DIGSPERLONG, 
+                        (xx < 0) ? SCM_BIGSIGNFLAG : 0, y, SCM_BIGSIGNFLAG);
 #endif
-      if (SCM_SLOPPY_COMPLEXP (y)) {
-       return scm_make_complex (SCM_INUM (x) - SCM_COMPLEX_REAL (y), 
-                                -SCM_COMPLEX_IMAG (y));
-      } else {
-       return scm_make_real (SCM_INUM (x) - SCM_REAL_VALUE (y));
-      }
+    } else if (SCM_REALP (y)) {
+      return scm_make_real (xx - SCM_REAL_VALUE (y));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (xx - SCM_COMPLEX_REAL (y),
+                              -SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARGn, s_difference);
     }
-  cx = SCM_INUM (x) - SCM_INUM (y);
- checkx:
-  if (SCM_FIXABLE (cx))
-    return SCM_MAKINUM (cx);
-#ifdef SCM_BIGDIG
-  return scm_long2big (cx);
+  } else if (SCM_BIGP (x)) {
+    if (SCM_INUMP (y)) {
+      long int yy = SCM_INUM (y);
+#ifndef SCM_DIGSTOOBIG
+      long z = scm_pseudolong (yy);
+      return scm_addbig ((SCM_BIGDIG *) & z, SCM_DIGSPERLONG,
+                        (yy < 0) ? 0 : SCM_BIGSIGNFLAG, x, 0);
 #else
-  return scm_make_real ((double) cx);
+      SCM_BIGDIG zdigs [SCM_DIGSPERLONG];
+      scm_longdigs (yy, zdigs);
+      return scm_addbig (zdigs, SCM_DIGSPERLONG, 
+                        (yy < 0) ? 0 : SCM_BIGSIGNFLAG, x, 0);
 #endif
+    } else if (SCM_BIGP (y)) {
+      return (SCM_NUMDIGS (x) < SCM_NUMDIGS (y))
+       ? scm_addbig (SCM_BDIGITS (x), SCM_NUMDIGS (x),
+                     SCM_BIGSIGN (x), y, SCM_BIGSIGNFLAG)
+       : scm_addbig (SCM_BDIGITS (y), SCM_NUMDIGS (y),
+                     SCM_BIGSIGN (y) ^ SCM_BIGSIGNFLAG, x, 0);
+    } else if (SCM_REALP (y)) {
+      return scm_make_real (scm_big2dbl (x) - SCM_REAL_VALUE (y));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (scm_big2dbl (x) - SCM_COMPLEX_REAL (y),
+                              - SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARGn, s_difference);
+    }
+  } else if (SCM_REALP (x)) {
+    if (SCM_INUMP (y)) {
+      return scm_make_real (SCM_REAL_VALUE (x) - SCM_INUM (y));
+    } else if (SCM_BIGP (y)) {
+      return scm_make_real (SCM_REAL_VALUE (x) - scm_big2dbl (y));
+    } else if (SCM_REALP (y)) {
+      return scm_make_real (SCM_REAL_VALUE (x) - SCM_REAL_VALUE (y));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (SCM_REAL_VALUE (x) - SCM_COMPLEX_REAL (y),
+                              -SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARGn, s_difference);
+    }
+  } else if (SCM_COMPLEXP (x)) {
+    if (SCM_INUMP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) - SCM_INUM (y),
+                              SCM_COMPLEX_IMAG (x));
+    } else if (SCM_BIGP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) - scm_big2dbl (y),
+                              SCM_COMPLEX_IMAG (x));
+    } else if (SCM_REALP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) - SCM_REAL_VALUE (y),
+                              SCM_COMPLEX_IMAG (x));
+    } else if (SCM_COMPLEXP (y)) {
+      return scm_make_complex (SCM_COMPLEX_REAL (x) - SCM_COMPLEX_REAL (y),
+                              SCM_COMPLEX_IMAG (x) - SCM_COMPLEX_IMAG (y));
+    } else {
+      SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARGn, s_difference);
+    }
+  } else {
+    SCM_WTA_DISPATCH_2 (g_difference, x, y, SCM_ARG1, s_difference);
+  }
 }
 
 
@@ -3953,60 +3885,31 @@ static void scm_two_doubles (SCM z1,
 static void
 scm_two_doubles (SCM z1, SCM z2, const char *sstring, struct dpair *xy)
 {
-  if (SCM_INUMP (z1))
+  if (SCM_INUMP (z1)) {
     xy->x = SCM_INUM (z1);
-  else
-    {
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (z1), badz1);
-      if (SCM_BIGP (z1))
-       xy->x = scm_big2dbl (z1);
-      else
-       {
-#ifndef SCM_RECKLESS
-         if (!SCM_SLOPPY_REALP (z1))
-           badz1:scm_wta (z1, (char *) SCM_ARG1, sstring);
-#endif
-         xy->x = SCM_REALPART (z1);
-       }
-#else
-      {
-       SCM_ASSERT (SCM_SLOPPY_REALP (z1), z1, SCM_ARG1, sstring);
-       xy->x = SCM_REALPART (z1);
-      }
-#endif
-    }
-  if (SCM_INUMP (z2))
+  } else if (SCM_BIGP (z1)) {
+    xy->x = scm_big2dbl (z1);
+  } else if (SCM_REALP (z1)) {
+    xy->x = SCM_REAL_VALUE (z1);
+  } else {
+    scm_wrong_type_arg (sstring, SCM_ARG1, z1);
+  }
+
+  if (SCM_INUMP (z2)) {
     xy->y = SCM_INUM (z2);
-  else
-    {
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (z2), badz2);
-      if (SCM_BIGP (z2))
-       xy->y = scm_big2dbl (z2);
-      else
-       {
-#ifndef SCM_RECKLESS
-         if (!(SCM_SLOPPY_REALP (z2)))
-           badz2:scm_wta (z2, (char *) SCM_ARG2, sstring);
-#endif
-         xy->y = SCM_REALPART (z2);
-       }
-#else
-      {
-       SCM_ASSERT (SCM_SLOPPY_REALP (z2), z2, SCM_ARG2, sstring);
-       xy->y = SCM_REALPART (z2);
-      }
-#endif
-    }
+  } else if (SCM_BIGP (z2)) {
+    xy->y = scm_big2dbl (z2);
+  } else if (SCM_REALP (z2)) {
+    xy->y = SCM_REAL_VALUE (z2);
+  } else {
+    scm_wrong_type_arg (sstring, SCM_ARG2, z2);
+  }
 }
 
 
-
-
 SCM_DEFINE (scm_sys_expt, "$expt", 2, 0, 0,
             (SCM z1, SCM z2),
-           "")
+           "") 
 #define FUNC_NAME s_scm_sys_expt
 {
   struct dpair xy;
@@ -4016,7 +3919,6 @@ SCM_DEFINE (scm_sys_expt, "$expt", 2, 0, 0,
 #undef FUNC_NAME
 
 
-
 SCM_DEFINE (scm_sys_atan2, "$atan2", 2, 0, 0,
             (SCM z1, SCM z2),
            "")
@@ -4029,14 +3931,14 @@ SCM_DEFINE (scm_sys_atan2, "$atan2", 2, 0, 0,
 #undef FUNC_NAME
 
 
-
 SCM_DEFINE (scm_make_rectangular, "make-rectangular", 2, 0, 0,
-            (SCM z1, SCM z2),
-           "")
+            (SCM real, SCM imaginary),
+           "Return a complex number constructed of the given REAL and\n"
+           "IMAGINARY parts.")
 #define FUNC_NAME s_scm_make_rectangular
 {
   struct dpair xy;
-  scm_two_doubles (z1, z2, FUNC_NAME, &xy);
+  scm_two_doubles (real, imaginary, FUNC_NAME, &xy);
   return scm_make_complex (xy.x, xy.y);
 }
 #undef FUNC_NAME
@@ -4045,7 +3947,7 @@ SCM_DEFINE (scm_make_rectangular, "make-rectangular", 2, 0, 0,
 
 SCM_DEFINE (scm_make_polar, "make-polar", 2, 0, 0,
             (SCM z1, SCM z2),
-           "")
+           "Return the complex number Z1 * e^(i * Z2).")
 #define FUNC_NAME s_scm_make_polar
 {
   struct dpair xy;
@@ -4055,94 +3957,80 @@ SCM_DEFINE (scm_make_polar, "make-polar", 2, 0, 0,
 #undef FUNC_NAME
 
 
-
-
 SCM_GPROC (s_real_part, "real-part", 1, 0, 0, scm_real_part, g_real_part);
 
 SCM
 scm_real_part (SCM z)
 {
-  if (SCM_NINUMP (z))
-    {
-#ifdef SCM_BIGDIG
-      SCM_ASRTGO (SCM_NIMP (z), badz);
-      if (SCM_BIGP (z))
-       return z;
-      if (!(SCM_SLOPPY_INEXACTP (z)))
-       {
-       badz:
-         SCM_WTA_DISPATCH_1 (g_real_part, z, SCM_ARG1, s_real_part);
-       }
-#else
-      SCM_GASSERT1 (SCM_SLOPPY_INEXACTP (z),
-                   g_real_part, z, SCM_ARG1, s_real_part);
-#endif
-      if (SCM_SLOPPY_COMPLEXP (z))
-       return scm_make_real (SCM_REAL (z));
-    }
-  return z;
+  if (SCM_INUMP (z)) {
+    return z;
+  } else if (SCM_BIGP (z)) {
+    return z;
+  } else if (SCM_REALP (z)) {
+    return z;
+  } else if (SCM_COMPLEXP (z)) {
+    return scm_make_real (SCM_COMPLEX_REAL (z));
+  } else {
+    SCM_WTA_DISPATCH_1 (g_real_part, z, SCM_ARG1, s_real_part);
+  }
 }
 
 
-
 SCM_GPROC (s_imag_part, "imag-part", 1, 0, 0, scm_imag_part, g_imag_part);
 
 SCM
 scm_imag_part (SCM z)
 {
-  if (SCM_INUMP (z))
+  if (SCM_INUMP (z)) {
     return SCM_INUM0;
-#ifdef SCM_BIGDIG
-  SCM_ASRTGO (SCM_NIMP (z), badz);
-  if (SCM_BIGP (z))
+  } else if (SCM_BIGP (z)) {
     return SCM_INUM0;
-  if (!(SCM_SLOPPY_INEXACTP (z)))
-    {
-    badz:
-      SCM_WTA_DISPATCH_1 (g_imag_part, z, SCM_ARG1, s_imag_part);
-    }
-#else
-  SCM_GASSERT1 (SCM_SLOPPY_INEXACTP (z),
-               g_imag_part, z, SCM_ARG1, s_imag_part);
-#endif
-  if (SCM_SLOPPY_COMPLEXP (z))
-    return scm_make_real (SCM_IMAG (z));
-  return scm_flo0;
+  } else if (SCM_REALP (z)) {
+    return scm_flo0;
+  } else if (SCM_COMPLEXP (z)) {
+    return scm_make_real (SCM_COMPLEX_IMAG (z));
+  } else {
+    SCM_WTA_DISPATCH_1 (g_imag_part, z, SCM_ARG1, s_imag_part);
+  }
 }
 
 
-
 SCM_GPROC (s_magnitude, "magnitude", 1, 0, 0, scm_magnitude, g_magnitude);
 
 SCM
 scm_magnitude (SCM z)
 {
-  if (SCM_INUMP (z))
-    return scm_abs (z);
+  if (SCM_INUMP (z)) {
+    long int zz = SCM_INUM (z);
+    if (zz >= 0) {
+      return z;
+    } else if (SCM_POSFIXABLE (-zz)) {
+      return SCM_MAKINUM (-zz);
+    } else {
 #ifdef SCM_BIGDIG
-  SCM_ASRTGO (SCM_NIMP (z), badz);
-  if (SCM_BIGP (z))
-    return scm_abs (z);
-  if (!(SCM_SLOPPY_INEXACTP (z)))
-    {
-    badz:
-      SCM_WTA_DISPATCH_1 (g_magnitude, z, SCM_ARG1, s_magnitude);
-    }
+      return scm_long2big (-zz);
 #else
-  SCM_GASSERT1 (SCM_SLOPPY_INEXACTP (z),
-               g_magnitude, z, SCM_ARG1, s_magnitude);
+      scm_num_overflow (s_magnitude);
 #endif
-  if (SCM_SLOPPY_COMPLEXP (z))
-    {
-      double i = SCM_IMAG (z), r = SCM_REAL (z);
-      return scm_make_real (sqrt (i * i + r * r));
     }
-  return scm_make_real (fabs (SCM_REALPART (z)));
+  } else if (SCM_BIGP (z)) {
+    if (!SCM_BIGSIGN (z)) {
+      return z;
+    } else {
+      return scm_copybig (z, 0);
+    }
+  } else if (SCM_REALP (z)) {
+    return scm_make_real (fabs (SCM_REAL_VALUE (z)));
+  } else if (SCM_COMPLEXP (z)) {
+    double r = SCM_COMPLEX_REAL (z);
+    double i = SCM_COMPLEX_IMAG (z);
+    return scm_make_real (sqrt (i * i + r * r));
+  } else {
+    SCM_WTA_DISPATCH_1 (g_magnitude, z, SCM_ARG1, s_magnitude);
+  }
 }
 
 
-
-
 SCM_GPROC (s_angle, "angle", 1, 0, 0, scm_angle, g_angle);
 
 SCM
@@ -4172,46 +4060,32 @@ scm_angle (SCM z)
 
 SCM_DEFINE (scm_inexact_to_exact, "inexact->exact", 1, 0, 0, 
             (SCM z),
-           "")
+           "Returns an exact number that is numerically closest to Z.")
 #define FUNC_NAME s_scm_inexact_to_exact
 {
-  if (SCM_INUMP (z))
+  if (SCM_INUMP (z)) {
     return z;
-#ifdef SCM_BIGDIG
-  SCM_ASRTGO (SCM_NIMP (z), badz);
-  if (SCM_BIGP (z))
+  } else if (SCM_BIGP (z)) {
     return z;
-#ifndef SCM_RECKLESS
-  if (!(SCM_SLOPPY_REALP (z)))
-    {
-    badz:
-      SCM_WTA (1, z);
-    }
-#endif
-#else
-  SCM_VALIDATE_REAL (1,z);
-#endif
+  } else if (SCM_REALP (z)) {
+    double u = floor (SCM_REAL_VALUE (z) + 0.5);
+    long lu = (long) u;
+    if (SCM_FIXABLE (lu)) {
+      return SCM_MAKINUM (lu);
 #ifdef SCM_BIGDIG
-  {
-    double u = floor (SCM_REALPART (z) + 0.5);
-    if ((u <= SCM_MOST_POSITIVE_FIXNUM) && (-u <= -SCM_MOST_NEGATIVE_FIXNUM))
-      {
-       /* Negation is a workaround for HP700 cc bug */
-       SCM ans = SCM_MAKINUM ((long) u);
-       if (SCM_INUM (ans) == (long) u)
-         return ans;
-      }
-    SCM_ASRTGO (isfinite (u), badz);   /* problem? */
-    return scm_dbl2big (u);
-  }
-#else
-  return SCM_MAKINUM ((long) floor (SCM_REALPART (z) + 0.5));
+    } else if (isfinite (u)) {
+      return scm_dbl2big (u);
 #endif
+    } else {
+      scm_num_overflow (s_scm_inexact_to_exact);
+    }
+  } else {
+    SCM_WRONG_TYPE_ARG (1, z);
+  }
 }
 #undef FUNC_NAME
 
 
-
 #ifdef SCM_BIGDIG
 /* d must be integer */
 
@@ -4295,8 +4169,8 @@ scm_long_long2num (long_long sl)
       return SCM_MAKINUM ((scm_bits_t) sl);
     }
 }
-#endif
 
+#endif /* HAVE_LONG_LONGS */
 
 
 SCM
@@ -4317,179 +4191,143 @@ scm_ulong2num (unsigned long sl)
 long
 scm_num2long (SCM num, char *pos, const char *s_caller)
 {
-  long res;
-
-  if (SCM_INUMP (num))
-    {
-      res = SCM_INUM (num);
-      return res;
+  if (SCM_INUMP (num)) {
+    return SCM_INUM (num);
+  } else if (SCM_BIGP (num)) {
+    long int res;
+    /* can't use res directly in case num is -2^31.  */
+    unsigned long int pos_res = 0;
+    unsigned long int old_res = 0;
+    scm_sizet l;
+
+    for (l = SCM_NUMDIGS (num); l--;) {
+      pos_res = SCM_BIGUP (pos_res) + SCM_BDIGITS (num)[l];
+      if (pos_res >= old_res) {
+       old_res = pos_res;
+      } else {
+       /* overflow. */
+       scm_out_of_range (s_caller, num);
+      }
     }
-  SCM_ASRTGO (SCM_NIMP (num), wrong_type_arg);
-  if (SCM_SLOPPY_REALP (num))
-    {
-      volatile double u = SCM_REALPART (num);
-
-      res = u;
-      if (res != u)
-       goto out_of_range;
-      return res;
+    if (SCM_BIGSIGN (num)) {
+      res = -pos_res;
+      if (res <= 0) {
+       return res;
+      } else {
+       scm_out_of_range (s_caller, num);
+      }
+    } else {
+      res = pos_res;
+      if (res >= 0) {
+       return res;
+      } else {
+       scm_out_of_range (s_caller, num);
+      }
     }
-#ifdef SCM_BIGDIG
-  if (SCM_BIGP (num))
-    {
-      unsigned long oldres = 0;
-      scm_sizet l;
-      /* can't use res directly in case num is -2^31.  */
-      unsigned long pos_res = 0;
-
-      for (l = SCM_NUMDIGS (num); l--;)
-       {
-         pos_res = SCM_BIGUP (pos_res) + SCM_BDIGITS (num)[l];
-         /* check for overflow.  */
-         if (pos_res < oldres) 
-           goto out_of_range;
-         oldres = pos_res;
-       }
-      if (SCM_BIGSIGN (num))
-       {
-         res = - pos_res;
-         if (res > 0)
-           goto out_of_range;
-       }
-      else
-       {
-         res = pos_res;
-         if (res < 0)
-           goto out_of_range;
-       }
+  } else if (SCM_REALP (num)) {
+    double u = SCM_REAL_VALUE (num);
+    long int res = u;
+    if ((double) res == u) {
       return res;
+    } else {
+      scm_out_of_range (s_caller, num);
     }
-#endif
- wrong_type_arg:
-  scm_wrong_type_arg (s_caller, (int) pos, num);
- out_of_range:
-  scm_out_of_range (s_caller, num);
+  } else {
+    scm_wrong_type_arg (s_caller, (int) pos, num);
+  }
 }
 
 
-
 #ifdef HAVE_LONG_LONGS
 
 long_long
 scm_num2long_long (SCM num, char *pos, const char *s_caller)
 {
-  long_long res;
-
-  if (SCM_INUMP (num))
-    {
-      res = SCM_INUM (num);
-      return res;
+  if (SCM_INUMP (num)) {
+    return SCM_INUM (num);
+  } else if (SCM_BIGP (num)) {
+    long long res;
+    /* can't use res directly in case num is -2^63.  */
+    unsigned long long int pos_res = 0;
+    unsigned long long int old_res = 0;
+    scm_sizet l;
+
+    for (l = SCM_NUMDIGS (num); l--;) {
+      pos_res = SCM_LONGLONGBIGUP (pos_res) + SCM_BDIGITS (num)[l];
+      if (pos_res >= old_res) {
+       old_res = pos_res;
+      } else {
+       /* overflow. */
+       scm_out_of_range (s_caller, num);
+      }
     }
-  SCM_ASRTGO (SCM_NIMP (num), wrong_type_arg);
-  if (SCM_SLOPPY_REALP (num))
-    {
-      double u = SCM_REALPART (num);
-
-      res = u;
-      if ((res < 0 && u > 0) || (res > 0 && u < 0)) /* check for overflow. */
-       goto out_of_range;
-
-      return res;
+    if (SCM_BIGSIGN (num)) {
+      res = -pos_res;
+      if (res <= 0) {
+       return res;
+      } else {
+       scm_out_of_range (s_caller, num);
+      }
+    } else {
+      res = pos_res;
+      if (res >= 0) {
+       return res;
+      } else {
+       scm_out_of_range (s_caller, num);
+      }
     }
-#ifdef SCM_BIGDIG
-  if (SCM_BIGP (num))
-    {
-      unsigned long long oldres = 0;
-      scm_sizet l;
-      /* can't use res directly in case num is -2^63.  */
-      unsigned long long pos_res = 0;
-
-      for (l = SCM_NUMDIGS (num); l--;)
-       {
-         pos_res = SCM_LONGLONGBIGUP (pos_res) + SCM_BDIGITS (num)[l];
-         /* check for overflow.  */
-         if (pos_res < oldres) 
-           goto out_of_range;
-         oldres = pos_res;
-       }
-      if (SCM_BIGSIGN (num))
-       {
-         res = - pos_res;
-         if (res > 0)
-           goto out_of_range;
-       }
-      else
-       {
-         res = pos_res;
-         if (res < 0)
-           goto out_of_range;
-       }
+  } else if (SCM_REALP (num)) {
+    double u = SCM_REAL_VALUE (num);
+    long long int res = u;
+    if ((double) res == u) {
       return res;
+    } else {
+      scm_out_of_range (s_caller, num);
     }
-#endif
- wrong_type_arg:
-  scm_wrong_type_arg (s_caller, (int) pos, num);
- out_of_range:
-  scm_out_of_range (s_caller, num);
+  } else {
+    scm_wrong_type_arg (s_caller, (int) pos, num);
+  }
 }
-#endif
 
+#endif /* HAVE_LONG_LONGS */
 
 
 unsigned long
 scm_num2ulong (SCM num, char *pos, const char *s_caller)
 {
-  unsigned long res;
-
-  if (SCM_INUMP (num))
-    {
-      if (SCM_INUM (num) < 0)
-       goto out_of_range;
-      res = SCM_INUM (num);
-      return res;
-    }
-  SCM_ASRTGO (SCM_NIMP (num), wrong_type_arg);
-  if (SCM_SLOPPY_REALP (num))
-    {
-      double u = SCM_REALPART (num);
-
-      res = u;
-      if (res != u)
-       goto out_of_range;
-      return res;
+  if (SCM_INUMP (num)) {
+    long nnum = SCM_INUM (num);
+    if (nnum >= 0) {
+      return nnum;
+    } else {
+      scm_out_of_range (s_caller, num);
+    }
+  } else if (SCM_BIGP (num)) {
+    unsigned long int res = 0;
+    unsigned long int old_res = 0;
+    scm_sizet l;
+    
+    for (l = SCM_NUMDIGS (num); l--;) {
+      res = SCM_BIGUP (res) + SCM_BDIGITS (num)[l];
+      if (res >= old_res) {
+       old_res = res;
+      } else {
+       scm_out_of_range (s_caller, num);
+      }
     }
-#ifdef SCM_BIGDIG
-  if (SCM_BIGP (num))
-    {
-      unsigned long oldres = 0;
-      scm_sizet l;
-
-      res = 0;
-      for (l = SCM_NUMDIGS (num); l--;)
-       {
-         res = SCM_BIGUP (res) + SCM_BDIGITS (num)[l];
-         if (res < oldres)
-           goto out_of_range;
-         oldres = res;
-       }
+    return res;
+  } else if (SCM_REALP (num)) {
+    double u = SCM_REAL_VALUE (num);
+    unsigned long int res = u;
+    if ((double) res == u) {
       return res;
+    } else {
+      scm_out_of_range (s_caller, num);
     }
-#endif
- wrong_type_arg:
-  scm_wrong_type_arg (s_caller, (int) pos, num);
- out_of_range:
-  scm_out_of_range (s_caller, num);
-}
-
-
-#ifndef DBL_DIG
-static void
-add1 (double f, double *fsum)
-{
-  *fsum = f + 1.0;
+  } else {
+    scm_wrong_type_arg (s_caller, (int) pos, num);
+  }
 }
-#endif
-
 
 
 void
@@ -4497,20 +4335,21 @@ scm_init_numbers ()
 {
   scm_add_feature ("complex");
   scm_add_feature ("inexact");
-  SCM_NEWREAL (scm_flo0, 0.0);
+  scm_flo0 = scm_make_real (0.0);
 #ifdef DBL_DIG
   scm_dblprec = (DBL_DIG > 20) ? 20 : DBL_DIG;
 #else
   {                            /* determine floating point precision */
     double f = 0.1;
     double fsum = 1.0 + f;
-    while (fsum != 1.0)
-      {
+    while (fsum != 1.0) {
+      if (++scm_dblprec > 20) {
+       fsum = 1.0;
+      } else {
        f /= 10.0;
-       if (++scm_dblprec > 20)
-         break;
-       add1 (f, &fsum);
+       fsum = f + 1.0;
       }
+    }
     scm_dblprec = scm_dblprec - 1;
   }
 #endif /* DBL_DIG */