comparison src/number.c @ 2061:b75af0ab66f3

[xemacs-hg @ 2004-05-05 22:09:14 by james] Use DEFINE_BASIC_LRECORD_IMPLEMENTATION for bignum, ratio, and bigfloat.
author james
date Wed, 05 May 2004 22:09:18 +0000
parents 471242c84954
children f557693c61de
comparison
equal deleted inserted replaced
2060:61e1c92f8f4e 2061:b75af0ab66f3
49 CIbyte *bstr = bignum_to_string (XBIGNUM_DATA (obj), 10); 49 CIbyte *bstr = bignum_to_string (XBIGNUM_DATA (obj), 10);
50 write_c_string (printcharfun, bstr); 50 write_c_string (printcharfun, bstr);
51 xfree (bstr, CIbyte *); 51 xfree (bstr, CIbyte *);
52 } 52 }
53 53
54 static void
55 bignum_finalize (void *header, int for_disksave)
56 {
57 if (for_disksave)
58 invalid_operation ("Can't dump an XEmacs containing bignum objects",
59 VOID_TO_LISP (header));
60 bignum_fini (((Lisp_Bignum *)header)->data);
61 }
62
63 static int 54 static int
64 bignum_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) 55 bignum_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
65 { 56 {
66 return bignum_eql (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)); 57 return bignum_eql (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2));
67 } 58 }
75 static const struct memory_description bignum_description[] = { 66 static const struct memory_description bignum_description[] = {
76 { XD_OPAQUE_PTR, offsetof (Lisp_Bignum, data) }, 67 { XD_OPAQUE_PTR, offsetof (Lisp_Bignum, data) },
77 { XD_END } 68 { XD_END }
78 }; 69 };
79 70
80 DEFINE_LRECORD_IMPLEMENTATION ("bignum", bignum, 0, 0, 71 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bignum", bignum, 0, 0, bignum_print,
81 bignum_print, bignum_finalize, bignum_equal, 72 0, bignum_equal, bignum_hash,
82 bignum_hash, bignum_description, Lisp_Bignum); 73 bignum_description, Lisp_Bignum);
83 74
84 #else /* !HAVE_BIGNUM */ 75 #else /* !HAVE_BIGNUM */
85 76
86 Lisp_Object Qbignump; 77 Lisp_Object Qbignump;
87 78
136 CIbyte *rstr = ratio_to_string (XRATIO_DATA (obj), 10); 127 CIbyte *rstr = ratio_to_string (XRATIO_DATA (obj), 10);
137 write_c_string (printcharfun, rstr); 128 write_c_string (printcharfun, rstr);
138 xfree (rstr, CIbyte *); 129 xfree (rstr, CIbyte *);
139 } 130 }
140 131
141 static void
142 ratio_finalize (void *header, int for_disksave)
143 {
144 if (for_disksave)
145 invalid_operation ("Can't dump an XEmacs containing ratio objects",
146 VOID_TO_LISP (header));
147 ratio_fini (((Lisp_Ratio *)header)->data);
148 }
149
150 static int 132 static int
151 ratio_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) 133 ratio_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
152 { 134 {
153 return ratio_eql (XRATIO_DATA (obj1), XRATIO_DATA (obj2)); 135 return ratio_eql (XRATIO_DATA (obj1), XRATIO_DATA (obj2));
154 } 136 }
162 static const struct memory_description ratio_description[] = { 144 static const struct memory_description ratio_description[] = {
163 { XD_OPAQUE_PTR, offsetof (Lisp_Ratio, data) }, 145 { XD_OPAQUE_PTR, offsetof (Lisp_Ratio, data) },
164 { XD_END } 146 { XD_END }
165 }; 147 };
166 148
167 DEFINE_LRECORD_IMPLEMENTATION ("ratio", ratio, 0, 0, 149 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("ratio", ratio, 0, 0, ratio_print,
168 ratio_print, ratio_finalize, ratio_equal, 150 0, ratio_equal, ratio_hash,
169 ratio_hash, ratio_description, Lisp_Ratio); 151 ratio_description, Lisp_Ratio);
170 152
171 #else /* !HAVE_RATIO */ 153 #else /* !HAVE_RATIO */
172 154
173 Lisp_Object Qratiop; 155 Lisp_Object Qratiop;
174 156
233 CIbyte *fstr = bigfloat_to_string (XBIGFLOAT_DATA (obj), 10); 215 CIbyte *fstr = bigfloat_to_string (XBIGFLOAT_DATA (obj), 10);
234 write_c_string (printcharfun, fstr); 216 write_c_string (printcharfun, fstr);
235 xfree (fstr, CIbyte *); 217 xfree (fstr, CIbyte *);
236 } 218 }
237 219
238 static void
239 bigfloat_finalize (void *header, int for_disksave)
240 {
241 if (for_disksave)
242 invalid_operation ("Can't dump an XEmacs containing bigfloat objects",
243 VOID_TO_LISP (header));
244 bigfloat_fini (((Lisp_Bigfloat *)header)->bf);
245 }
246
247 static int 220 static int
248 bigfloat_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) 221 bigfloat_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
249 { 222 {
250 return bigfloat_eql (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)); 223 return bigfloat_eql (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2));
251 } 224 }
259 static const struct memory_description bigfloat_description[] = { 232 static const struct memory_description bigfloat_description[] = {
260 { XD_OPAQUE_PTR, offsetof (Lisp_Bigfloat, bf) }, 233 { XD_OPAQUE_PTR, offsetof (Lisp_Bigfloat, bf) },
261 { XD_END } 234 { XD_END }
262 }; 235 };
263 236
264 DEFINE_LRECORD_IMPLEMENTATION ("bigfloat", bigfloat, 1, 0, 237 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bigfloat", bigfloat, 1, 0,
265 bigfloat_print, bigfloat_finalize, 238 bigfloat_print, 0,
266 bigfloat_equal, bigfloat_hash, 239 bigfloat_equal, bigfloat_hash,
267 bigfloat_description, Lisp_Bigfloat); 240 bigfloat_description, Lisp_Bigfloat);
268 241
269 #else /* !HAVE_BIGFLOAT */ 242 #else /* !HAVE_BIGFLOAT */
270 243
271 Lisp_Object Qbigfloatp; 244 Lisp_Object Qbigfloatp;
272 245
741 DEFVAR_CONST_LISP ("bigfloat-max-prec", &Vbigfloat_max_prec /* 714 DEFVAR_CONST_LISP ("bigfloat-max-prec", &Vbigfloat_max_prec /*
742 The maximum number of bits of precision a bigfloat can have. 715 The maximum number of bits of precision a bigfloat can have.
743 This is currently the value of ULONG_MAX on the target machine. 716 This is currently the value of ULONG_MAX on the target machine.
744 */); 717 */);
745 718
746 /* See init_number for the other half of Vbigfloat_max_prec initialization */ 719 #ifdef HAVE_BIGFLOAT
747 #if defined(HAVE_BIGFLOAT) && !defined(HAVE_BIGNUM) 720 #ifdef HAVE_BIGNUM
721 /* Uncomment the next two lines and remove the line below them when dumping
722 bignums becomes possible. */
723 /*
724 Vbigfloat_max_prec = make_bignum (0L);
725 bignum_set_ulong (XBIGNUM_DATA (Vbigfloat_max_prec), ULONG_MAX);
726 */
748 Vbigfloat_max_prec = make_int (EMACS_INT_MAX); 727 Vbigfloat_max_prec = make_int (EMACS_INT_MAX);
728 #else
729 Vbigfloat_max_prec = make_int (EMACS_INT_MAX);
730 #endif
749 #else 731 #else
750 Vbigfloat_max_prec = make_int (0); 732 Vbigfloat_max_prec = make_int (0);
751 #endif /* HAVE_BIGFLOAT */ 733 #endif /* HAVE_BIGFLOAT */
752 734
753 DEFVAR_CONST_INT ("most-negative-fixnum", &Vmost_negative_fixnum /* 735 DEFVAR_CONST_INT ("most-negative-fixnum", &Vmost_negative_fixnum /*
798 #ifdef HAVE_BIGFLOAT 780 #ifdef HAVE_BIGFLOAT
799 bigfloat_init (scratch_bigfloat); 781 bigfloat_init (scratch_bigfloat);
800 bigfloat_init (scratch_bigfloat2); 782 bigfloat_init (scratch_bigfloat2);
801 #endif 783 #endif
802 } 784 }
803 785 }
804 #if defined(HAVE_BIGFLOAT) && defined(HAVE_BIGNUM)
805 /* Avoid dumping a bignum */
806 if (initialized)
807 {
808 Vbigfloat_max_prec = make_bignum (0L);
809 bignum_set_ulong (XBIGNUM_DATA (Vbigfloat_max_prec), ULONG_MAX);
810 }
811 #endif
812 }