summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Herrmann <dirk@dirk-herrmanns-seiten.de>2001-10-05 17:43:49 +0000
committerDirk Herrmann <dirk@dirk-herrmanns-seiten.de>2001-10-05 17:43:49 +0000
commit14282d0f5c839816aff0e83466b6ea46e51cdac0 (patch)
tree354985edd41850cc53c9096829f1b867e987471b
parent74e0de864ba9eab0bf5190a3a4788599eacbcff2 (diff)
downloadguile-14282d0f5c839816aff0e83466b6ea46e51cdac0.tar.gz
* numbers.h: Removed old comment about using SCM_CAR to access
non-pair cells. (SCM_MOST_POSITIVE_FIXNUM, SCM_MOST_NEGATIVE_FIXNUM): Make sure the return value is signed. Thanks to Brian Crowder for the bug report. (SCM_SRS): Avoid unnecessary casting and don't unpack input values. With this patch, SCM_SRS can be safely used for other types than scm_t_signed_bits. However, it should still better be an internal macro and thus be renamed to SCM_I_SRS. (SCM_MAKINUM, SCM_INUM): Use proper casting.
-rw-r--r--THANKS1
-rw-r--r--libguile/ChangeLog16
-rw-r--r--libguile/numbers.h29
3 files changed, 30 insertions, 16 deletions
diff --git a/THANKS b/THANKS
index 1eb38dc64..2d74681dd 100644
--- a/THANKS
+++ b/THANKS
@@ -11,5 +11,6 @@ For fixes or providing information which led to a fix:
Martin Baulig
Rob Browning
+ Brian Crowder
Christopher Cramer
John Goerzen
diff --git a/libguile/ChangeLog b/libguile/ChangeLog
index 2a994253a..84b3e814c 100644
--- a/libguile/ChangeLog
+++ b/libguile/ChangeLog
@@ -1,3 +1,19 @@
+2001-10-05 Dirk Herrmann <D.Herrmann@tu-bs.de>
+
+ * numbers.h: Removed old comment about using SCM_CAR to access
+ non-pair cells.
+
+ (SCM_MOST_POSITIVE_FIXNUM, SCM_MOST_NEGATIVE_FIXNUM): Make sure
+ the return value is signed. Thanks to Brian Crowder for the bug
+ report.
+
+ (SCM_SRS): Avoid unnecessary casting and don't unpack input
+ values. With this patch, SCM_SRS can be safely used for other
+ types than scm_t_signed_bits. However, it should still better be
+ an internal macro and thus be renamed to SCM_I_SRS.
+
+ (SCM_MAKINUM, SCM_INUM): Use proper casting.
+
2001-10-03 Gary Houston <ghouston@arglist.com>
* continuations.h, unif.h: in the descriptions of the bit patterns
diff --git a/libguile/numbers.h b/libguile/numbers.h
index 350f43f3d..d12578127 100644
--- a/libguile/numbers.h
+++ b/libguile/numbers.h
@@ -51,39 +51,36 @@
-/* Immediate Numbers
+/* Immediate Numbers, also known as fixnums
*
- * Inums are exact integer data that fits within an SCM word.
- *
- * SCM_INUMP applies only to values known to be Scheme objects.
- * In particular, SCM_INUMP (SCM_CAR (x)) is valid only if x is known
- * to be a SCM_CONSP. If x is only known to be a non-immediate,
- * SCM_INUMP (SCM_CAR (x)) can give wrong answers.
- */
+ * Inums are exact integer data that fits within an SCM word. */
-#define SCM_I_FIXNUM_BIT (SCM_LONG_BIT - 2)
-#define SCM_MOST_POSITIVE_FIXNUM ((1L << (SCM_I_FIXNUM_BIT - 1)) - 1)
-#define SCM_MOST_NEGATIVE_FIXNUM (-SCM_MOST_POSITIVE_FIXNUM - 1)
+#define SCM_I_FIXNUM_BIT \
+ (SCM_LONG_BIT - 2)
+#define SCM_MOST_POSITIVE_FIXNUM \
+ ((((scm_t_signed_bits) 1) << (SCM_I_FIXNUM_BIT - 1)) - 1)
+#define SCM_MOST_NEGATIVE_FIXNUM \
+ (-((scm_t_signed_bits) SCM_MOST_POSITIVE_FIXNUM) - 1)
/* SCM_SRS is signed right shift */
#if (-1 == (((-1) << 2) + 2) >> 2)
-# define SCM_SRS(x, y) ((scm_t_signed_bits)(x) >> (y))
+# define SCM_SRS(x, y) ((x) >> (y))
#else
-# define SCM_SRS(x, y) ((SCM_UNPACK (x) < 0) ? ~((~SCM_UNPACK (x)) >> (y)) : (SCM_UNPACK (x) >> (y)))
+# define SCM_SRS(x, y) ((x) < 0 ? ~((~(x)) >> (y)) : ((x) >> (y)))
#endif /* (-1 == (((-1) << 2) + 2) >> 2) */
#define SCM_INUMP(x) (2 & SCM_UNPACK (x))
#define SCM_NINUMP(x) (!SCM_INUMP (x))
-#define SCM_MAKINUM(x) (SCM_PACK (((x) << 2) + 2L))
-#define SCM_INUM(x) ((scm_t_signed_bits)(SCM_SRS (SCM_UNPACK (x), 2)))
+#define SCM_MAKINUM(x) (SCM_PACK ((((scm_t_signed_bits) (x)) << 2) + 2))
+#define SCM_INUM(x) (SCM_SRS ((scm_t_signed_bits) SCM_UNPACK (x), 2))
/* SCM_FIXABLE is true if its long argument can be encoded in an SCM_INUM. */
#define SCM_POSFIXABLE(n) ((n) <= SCM_MOST_POSITIVE_FIXNUM)
#define SCM_NEGFIXABLE(n) ((n) >= SCM_MOST_NEGATIVE_FIXNUM)
-#define SCM_FIXABLE(n) (SCM_POSFIXABLE(n) && SCM_NEGFIXABLE(n))
+#define SCM_FIXABLE(n) (SCM_POSFIXABLE (n) && SCM_NEGFIXABLE (n))
/* A name for 0. */