* num2integral.i.c (NUM2INTEGRAL): Fixed signedness problem.
authorDirk Herrmann <dirk@dirk-herrmanns-seiten.de>
Mon, 25 Feb 2002 22:48:21 +0000 (22:48 +0000)
committerDirk Herrmann <dirk@dirk-herrmanns-seiten.de>
Mon, 25 Feb 2002 22:48:21 +0000 (22:48 +0000)
libguile/ChangeLog
libguile/num2integral.i.c

index bc17890..fc6852e 100644 (file)
@@ -1,3 +1,7 @@
+2002-01-10  Dirk Herrmann  <D.Herrmann@tu-bs.de>
+
+       * num2integral.i.c (NUM2INTEGRAL): Fixed signedness problem.
+
 2002-02-25  Gary Houston  <ghouston@arglist.com>
 
        * convert.c: include <string.h> for convert_i.c.
index b6e8a9b..a9bd5c7 100644 (file)
@@ -27,17 +27,21 @@ NUM2INTEGRAL (SCM num, unsigned long int pos, const char *s_caller)
         scm_out_of_range (s_caller, num);
 #endif
     
-      if (sizeof (ITYPE) >= sizeof (scm_t_signed_bits))
-        /* can't fit anything too big for this type in an inum
-           anyway */
-        return (ITYPE) n;
-      else
-        { /* an inum can be out of range, so check */
-         if (((ITYPE)n) != n)
-            scm_out_of_range (s_caller, num);
-          else
-            return (ITYPE) n;
-        }
+#if SIZEOF_ITYPE >= SIZEOF_SCM_T_BITS
+      /* the target type is large enough to hold any possible inum */
+      return (ITYPE) n;
+#else
+      /* an inum can be out of range, so check */
+#ifdef UNSIGNED
+      /* n is known to be >= 0 */
+      if ((scm_t_bits) n > UNSIGNED_ITYPE_MAX)
+       scm_out_of_range (s_caller, num);
+#else
+      if (((ITYPE)n) != n)
+       scm_out_of_range (s_caller, num);
+#endif
+      return (ITYPE) n;
+#endif /* SIZEOF_ITYPE >= SIZEOF_SCM_T_BITS */
     }
   else if (SCM_BIGP (num))
     { /* bignum */
@@ -78,9 +82,9 @@ NUM2INTEGRAL (SCM num, unsigned long int pos, const char *s_caller)
             scm_out_of_range (s_caller, num);
         }
 #endif
-      
+
 #else /* SIZEOF_ITYPE >= SIZEOF_SCM_T_BITS */
-            scm_out_of_range (s_caller, num);
+      scm_out_of_range (s_caller, num);
 #endif
       
     }