changeset 3391:639cdee384e4

[xemacs-hg @ 2006-05-10 15:03:35 by james] Fix bignum arithmetic on 64-bit platforms. See xemacs-patches message with ID <m364kg9nnq.fsf@jerrypc.cs.usu.edu>.
author james
date Wed, 10 May 2006 15:03:35 +0000
parents 1a44d3ebacc1
children 824c3c18a129
files src/ChangeLog src/number.c src/number.h
diffstat 3 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue May 09 21:51:20 2006 +0000
+++ b/src/ChangeLog	Wed May 10 15:03:35 2006 +0000
@@ -1,3 +1,10 @@
+2006-05-08  Jerry James  <james@xemacs.org>
+
+	* number.c (Fcanonicalize_number): Use EMACS_INT instead of int,
+	which fixes bignum arithmetic on 64-bit platforms.
+	* number.h (bignum_fits_emacs_int_p): New macro.
+	* number.h (bignum_to_emacs_int): New macro.
+
 2006-03-30  Stephen J. Turnbull  <stephen@xemacs.org>
 
 	* objects-x.c (x_initialize_font_instance):
--- a/src/number.c	Tue May 09 21:51:20 2006 +0000
+++ b/src/number.c	Wed May 10 15:03:35 2006 +0000
@@ -408,9 +408,9 @@
     number = make_bignum_bg (XRATIO_NUMERATOR (number));
 #endif
 #ifdef HAVE_BIGNUM
-  if (BIGNUMP (number) && bignum_fits_int_p (XBIGNUM_DATA (number)))
+  if (BIGNUMP (number) && bignum_fits_emacs_int_p (XBIGNUM_DATA (number)))
     {
-      int n = bignum_to_int (XBIGNUM_DATA (number));
+      EMACS_INT n = bignum_to_emacs_int (XBIGNUM_DATA (number));
       if (NUMBER_FITS_IN_AN_EMACS_INT (n))
 	number = make_int (n);
     }
--- a/src/number.h	Tue May 09 21:51:20 2006 +0000
+++ b/src/number.h	Wed May 10 15:03:35 2006 +0000
@@ -100,6 +100,16 @@
   return Fcanonicalize_number (retval);				\
 } while (0)
 
+#if SIZEOF_EMACS_INT == SIZEOF_LONG
+# define bignum_fits_emacs_int_p(b) bignum_fits_long_p(b)
+# define bignum_to_emacs_int(b) bignum_to_long(b)
+#elif SIZEOF_EMACS_INT == SIZEOF_INT
+# define bignum_fits_emacs_int_p(b) bignum_fits_int_p(b)
+# define bignum_to_emacs_int(b) bignum_to_int(b)
+#else
+# error Bignums currently do not work with long long Emacs integers.
+#endif
+
 extern Lisp_Object make_bignum (long);
 extern Lisp_Object make_bignum_bg (bignum);
 extern bignum scratch_bignum, scratch_bignum2;