diff src/data.c @ 5736:3192994c49ca

Convert C (un)signed long long values to bignums properly. This patch also does the following: - Uses make_fixnum instead of make_integer when the argument is guaranteed to be in the fixnum range. - Introduces make_unsigned_integer so that we handle unsigned values with the high bit set correctly. - Introduces conversions between bignums and (un)signed long long values. - Uses mp_set_memory_functions with the BSD MP code, if it exists. - Eliminates some unnecessary consing in the Lisp + and * implementations. - Fixes a problem with check_valid_xbm_inline(). This function is called during intialization. It calls Ftimes. When using pdump, this is a problem, because (a) the bignum code is not initialized until *after* dumping, so we don't try to dump any bignums, and (b) multiplication of integers is done inside bignums so we handle fixnum overflow correctly. I decided that an XBM file with dimensions that don't fit into fixnums is probably not something we want to try to handle anyway, and did the arithmetic with C values instead of Lisp values. Doing that broke one test, which started getting a different error message from the one it expected, so I adjusted the test to match the new reality. - Fixes a few miscellaneous bugs in the BSD MP code. See <CAHCOHQk0u0=eD1fUMHTNWi2Yh=1WgiYyCXdMbsGzHBNhdqYz4w@mail.gmail.com> in xemacs-patches, as well as followup messages.
author Jerry James <james@xemacs.org>
date Mon, 17 Jun 2013 10:23:00 -0600
parents 873d7425c1ad
children 70a3f4ff8da8
line wrap: on
line diff
--- a/src/data.c	Wed Apr 24 20:16:14 2013 -0400
+++ b/src/data.c	Mon Jun 17 10:23:00 2013 -0600
@@ -1447,16 +1447,14 @@
 	  break;
 #ifdef HAVE_BIGNUM
 	case BIGNUM_T:
-	  bignum_add (scratch_bignum, XBIGNUM_DATA (accum),
+	  bignum_add (XBIGNUM_DATA (accum), XBIGNUM_DATA (accum),
 		      XBIGNUM_DATA (addend));
-	  accum = make_bignum_bg (scratch_bignum);
 	  break;
 #endif
 #ifdef HAVE_RATIO
 	case RATIO_T:
-	  ratio_add (scratch_ratio, XRATIO_DATA (accum),
+	  ratio_add (XRATIO_DATA (accum), XRATIO_DATA (accum),
 		     XRATIO_DATA (addend));
-	  accum = make_ratio_rt (scratch_ratio);
 	  break;
 #endif
 	case FLOAT_T:
@@ -1464,12 +1462,11 @@
 	  break;
 #ifdef HAVE_BIGFLOAT
 	case BIGFLOAT_T:
-	  bigfloat_set_prec (scratch_bigfloat,
+	  bigfloat_set_prec (XBIGFLOAT_DATA (accum),
 			     max (XBIGFLOAT_GET_PREC (addend),
 				  XBIGFLOAT_GET_PREC (accum)));
-	  bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (accum),
+	  bigfloat_add (XBIGFLOAT_DATA (accum), XBIGFLOAT_DATA (accum),
 			XBIGFLOAT_DATA (addend));
-	  accum = make_bigfloat_bf (scratch_bigfloat);
 	  break;
 #endif
 	}
@@ -1643,16 +1640,14 @@
 	{
 #ifdef HAVE_BIGNUM
 	case BIGNUM_T:
-	  bignum_mul (scratch_bignum, XBIGNUM_DATA (accum),
+	  bignum_mul (XBIGNUM_DATA (accum), XBIGNUM_DATA (accum),
 		      XBIGNUM_DATA (multiplier));
-	  accum = make_bignum_bg (scratch_bignum);
 	  break;
 #endif
 #ifdef HAVE_RATIO
 	case RATIO_T:
-	  ratio_mul (scratch_ratio, XRATIO_DATA (accum),
+	  ratio_mul (XRATIO_DATA (accum), XRATIO_DATA (accum),
 		     XRATIO_DATA (multiplier));
-	  accum = make_ratio_rt (scratch_ratio);
 	  break;
 #endif
 	case FLOAT_T:
@@ -1660,12 +1655,11 @@
 	  break;
 #ifdef HAVE_BIGFLOAT
 	case BIGFLOAT_T:
-	  bigfloat_set_prec (scratch_bigfloat,
+	  bigfloat_set_prec (XBIGFLOAT_DATA (accum),
 			     max (XBIGFLOAT_GET_PREC (multiplier),
 				  XBIGFLOAT_GET_PREC (accum)));
-	  bigfloat_mul (scratch_bigfloat, XBIGFLOAT_DATA (accum),
+	  bigfloat_mul (XBIGFLOAT_DATA (accum), XBIGFLOAT_DATA (accum),
 			XBIGFLOAT_DATA (multiplier));
-	  accum = make_bigfloat_bf (scratch_bigfloat);
 	  break;
 #endif
 	}