guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

UNSIGNED_ITYPE_MAX signed?


From: Dirk Herrmann
Subject: UNSIGNED_ITYPE_MAX signed?
Date: Thu, 22 Nov 2001 20:05:53 +0100 (MET)

Hello,

is it a bug or a feature that UNSIGNED_ITYPE_MAX is a signed value?
UNSIGNED_ITYPE_MAX is defined as:

#define UNSIGNED_ITYPE_MAX (~((UNSIGNED_ITYPE)0))

I would expect it to be an unsigned value.  However, I have applied the
patch below to num2integral.i.c, and it just does not work (giving errors
in srfi-4) or gives 'comparing signed and unsigned' warnings if I leave
out the cast operations in the line after the FIXME comment.

What's the reason?

Best regards
Dirk Herrmann


Index: num2integral.i.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/num2integral.i.c,v
retrieving revision 1.13
diff -u -r1.13 num2integral.i.c
--- num2integral.i.c    2001/11/12 01:12:37     1.13
+++ num2integral.i.c    2001/11/22 18:59:55
@@ -27,17 +27,22 @@
         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
+      /* 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 */
+#ifdef UNSIGNED
+      /* n is known to be >= 0 */
+      /* Dirk:FIXME:: UNSIGNED_ITYPE_MAX is a signed value? gcc bug? */
+      if ((scm_t_bits) n > (UNSIGNED_ITYPE) 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 */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]