Mercurial > hg > xemacs-beta
annotate src/number.c @ 4895:65ad2cd9f2ff
Automated merge with http://hg.debian.org/hg/xemacs/xemacs
| author | Ben Wing <ben@xemacs.org> |
|---|---|
| date | Fri, 29 Jan 2010 15:06:36 -0600 |
| parents | d1d4ce10c7b4 |
| children | 6ef8256a020a bd169a24a554 |
| rev | line source |
|---|---|
| 1983 | 1 /* Numeric types for XEmacs. |
| 2 Copyright (C) 2004 Jerry James. | |
| 3 | |
| 4 This file is part of XEmacs. | |
| 5 | |
| 6 XEmacs is free software; you can redistribute it and/or modify it | |
| 7 under the terms of the GNU General Public License as published by the | |
| 8 Free Software Foundation; either version 2, or (at your option) any | |
| 9 later version. | |
| 10 | |
| 11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
| 17 along with XEmacs; see the file COPYING. If not, write to | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
18 the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
19 Boston, MA 02111-1301, USA. */ |
| 1983 | 20 |
| 21 /* Synched up with: Not in FSF. */ | |
| 22 | |
| 23 #include <config.h> | |
| 24 #include <limits.h> | |
| 25 #include "lisp.h" | |
| 26 | |
| 2595 | 27 #ifdef HAVE_BIGFLOAT |
| 28 #define USED_IF_BIGFLOAT(decl) decl | |
| 29 #else | |
| 30 #define USED_IF_BIGFLOAT(decl) UNUSED (decl) | |
| 31 #endif | |
| 32 | |
| 2001 | 33 Lisp_Object Qrationalp, Qfloatingp, Qrealp; |
| 1983 | 34 Lisp_Object Vdefault_float_precision; |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
35 |
| 1983 | 36 static Lisp_Object Qunsupported_type; |
| 37 static Lisp_Object Vbigfloat_max_prec; | |
| 38 static int number_initialized; | |
| 39 | |
| 40 #ifdef HAVE_BIGNUM | |
| 41 bignum scratch_bignum, scratch_bignum2; | |
| 42 #endif | |
| 43 #ifdef HAVE_RATIO | |
|
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3391
diff
changeset
|
44 ratio scratch_ratio, scratch_ratio2; |
| 1983 | 45 #endif |
| 46 #ifdef HAVE_BIGFLOAT | |
| 47 bigfloat scratch_bigfloat, scratch_bigfloat2; | |
| 48 #endif | |
| 49 | |
| 50 /********************************* Bignums **********************************/ | |
| 51 #ifdef HAVE_BIGNUM | |
| 52 static void | |
| 2286 | 53 bignum_print (Lisp_Object obj, Lisp_Object printcharfun, |
| 54 int UNUSED (escapeflag)) | |
| 1983 | 55 { |
| 56 CIbyte *bstr = bignum_to_string (XBIGNUM_DATA (obj), 10); | |
| 57 write_c_string (printcharfun, bstr); | |
| 58 xfree (bstr, CIbyte *); | |
| 59 } | |
| 60 | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
61 #ifdef NEW_GC |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
62 static void |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
63 bignum_finalize (void *header, int for_disksave) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
64 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
65 if (!for_disksave) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
66 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
67 struct Lisp_Bignum *num = (struct Lisp_Bignum *) header; |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
68 bignum_fini (num->data); |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
69 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
70 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
71 #define BIGNUM_FINALIZE bignum_finalize |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
72 #else |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
73 #define BIGNUM_FINALIZE 0 |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
74 #endif |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
75 |
| 1983 | 76 static int |
| 2286 | 77 bignum_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth)) |
| 1983 | 78 { |
| 79 return bignum_eql (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)); | |
| 80 } | |
| 81 | |
| 82 static Hashcode | |
| 2286 | 83 bignum_hash (Lisp_Object obj, int UNUSED (depth)) |
| 1983 | 84 { |
| 85 return bignum_hashcode (XBIGNUM_DATA (obj)); | |
| 86 } | |
| 87 | |
| 2551 | 88 static void |
| 89 bignum_convert (const void *object, void **data, Bytecount *size) | |
| 90 { | |
| 91 CIbyte *bstr = bignum_to_string (*(bignum *)object, 10); | |
| 92 *data = bstr; | |
| 93 *size = strlen(bstr)+1; | |
| 94 } | |
| 95 | |
| 96 static void | |
| 97 bignum_convfree (const void * UNUSED (object), void *data, | |
| 98 Bytecount UNUSED (size)) | |
| 99 { | |
| 100 xfree (data, void *); | |
| 101 } | |
| 102 | |
| 103 static void * | |
| 104 bignum_deconvert (void *object, void *data, Bytecount UNUSED (size)) | |
| 105 { | |
| 106 bignum *b = (bignum *) object; | |
| 107 bignum_init(*b); | |
| 108 bignum_set_string(*b, (const char *) data, 10); | |
| 109 return object; | |
| 110 } | |
| 111 | |
| 112 static const struct opaque_convert_functions bignum_opc = { | |
| 113 bignum_convert, | |
| 114 bignum_convfree, | |
| 115 bignum_deconvert | |
| 116 }; | |
| 117 | |
| 1983 | 118 static const struct memory_description bignum_description[] = { |
| 2551 | 119 { XD_OPAQUE_DATA_CONVERTIBLE, offsetof (Lisp_Bignum, data), |
| 120 0, { &bignum_opc }, XD_FLAG_NO_KKCC }, | |
| 1983 | 121 { XD_END } |
| 122 }; | |
| 123 | |
| 2551 | 124 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bignum", bignum, 1, 0, bignum_print, |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
125 BIGNUM_FINALIZE, bignum_equal, |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
126 bignum_hash, bignum_description, |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
127 Lisp_Bignum); |
| 1983 | 128 |
| 2092 | 129 #endif /* HAVE_BIGNUM */ |
| 1983 | 130 |
| 131 Lisp_Object Qbignump; | |
| 132 | |
| 133 DEFUN ("bignump", Fbignump, 1, 1, 0, /* | |
| 134 Return t if OBJECT is a bignum, nil otherwise. | |
| 135 */ | |
| 136 (object)) | |
| 137 { | |
| 138 return BIGNUMP (object) ? Qt : Qnil; | |
| 139 } | |
| 140 | |
| 141 | |
| 142 /********************************** Ratios **********************************/ | |
| 143 #ifdef HAVE_RATIO | |
| 144 static void | |
| 2286 | 145 ratio_print (Lisp_Object obj, Lisp_Object printcharfun, |
| 146 int UNUSED (escapeflag)) | |
| 1983 | 147 { |
| 148 CIbyte *rstr = ratio_to_string (XRATIO_DATA (obj), 10); | |
| 149 write_c_string (printcharfun, rstr); | |
| 150 xfree (rstr, CIbyte *); | |
| 151 } | |
| 152 | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
153 #ifdef NEW_GC |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
154 static void |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
155 ratio_finalize (void *header, int for_disksave) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
156 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
157 if (!for_disksave) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
158 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
159 struct Lisp_Ratio *num = (struct Lisp_Ratio *) header; |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
160 ratio_fini (num->data); |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
161 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
162 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
163 #define RATIO_FINALIZE ratio_finalize |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
164 #else |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
165 #define RATIO_FINALIZE 0 |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
166 #endif |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
167 |
| 1983 | 168 static int |
| 2286 | 169 ratio_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth)) |
| 1983 | 170 { |
| 171 return ratio_eql (XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
| 172 } | |
| 173 | |
| 174 static Hashcode | |
| 2286 | 175 ratio_hash (Lisp_Object obj, int UNUSED (depth)) |
| 1983 | 176 { |
| 177 return ratio_hashcode (XRATIO_DATA (obj)); | |
| 178 } | |
| 179 | |
| 180 static const struct memory_description ratio_description[] = { | |
| 181 { XD_OPAQUE_PTR, offsetof (Lisp_Ratio, data) }, | |
| 182 { XD_END } | |
| 183 }; | |
| 184 | |
| 2061 | 185 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("ratio", ratio, 0, 0, ratio_print, |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
186 RATIO_FINALIZE, ratio_equal, ratio_hash, |
| 2061 | 187 ratio_description, Lisp_Ratio); |
| 1983 | 188 |
| 2092 | 189 #endif /* HAVE_RATIO */ |
| 1983 | 190 |
| 191 Lisp_Object Qratiop; | |
| 192 | |
| 193 DEFUN ("ratiop", Fratiop, 1, 1, 0, /* | |
| 194 Return t if OBJECT is a ratio, nil otherwise. | |
| 195 */ | |
| 196 (object)) | |
| 197 { | |
| 198 return RATIOP (object) ? Qt : Qnil; | |
| 199 } | |
| 200 | |
| 201 | |
| 202 /******************************** Rationals *********************************/ | |
| 203 DEFUN ("rationalp", Frationalp, 1, 1, 0, /* | |
| 204 Return t if OBJECT is a rational, nil otherwise. | |
| 205 */ | |
| 206 (object)) | |
| 207 { | |
| 208 return RATIONALP (object) ? Qt : Qnil; | |
| 209 } | |
| 210 | |
| 211 DEFUN ("numerator", Fnumerator, 1, 1, 0, /* | |
| 212 Return the numerator of the canonical form of RATIONAL. | |
| 213 If RATIONAL is an integer, RATIONAL is returned. | |
| 214 */ | |
| 215 (rational)) | |
| 216 { | |
| 217 CONCHECK_RATIONAL (rational); | |
| 218 #ifdef HAVE_RATIO | |
|
4883
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
219 if (RATIOP (rational)) |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
220 { |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
221 return |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
222 Fcanonicalize_number (make_bignum_bg (XRATIO_NUMERATOR (rational))); |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
223 } |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
224 #endif |
| 1983 | 225 return rational; |
| 226 } | |
| 227 | |
| 228 DEFUN ("denominator", Fdenominator, 1, 1, 0, /* | |
| 229 Return the denominator of the canonical form of RATIONAL. | |
| 230 If RATIONAL is an integer, 1 is returned. | |
| 231 */ | |
| 232 (rational)) | |
| 233 { | |
| 234 CONCHECK_RATIONAL (rational); | |
| 235 #ifdef HAVE_RATIO | |
|
4883
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
236 if (RATIOP (rational)) |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
237 { |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
238 return Fcanonicalize_number (make_bignum_bg |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
239 (XRATIO_DENOMINATOR (rational))); |
|
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
240 } |
|
4892
d1d4ce10c7b4
Fix the build problem in number.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4886
diff
changeset
|
241 #endif |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
242 return make_int (1); |
| 1983 | 243 } |
| 244 | |
| 245 | |
| 246 /******************************** Bigfloats *********************************/ | |
| 247 #ifdef HAVE_BIGFLOAT | |
| 248 static void | |
| 2286 | 249 bigfloat_print (Lisp_Object obj, Lisp_Object printcharfun, |
| 250 int UNUSED (escapeflag)) | |
| 1983 | 251 { |
| 252 CIbyte *fstr = bigfloat_to_string (XBIGFLOAT_DATA (obj), 10); | |
| 253 write_c_string (printcharfun, fstr); | |
| 254 xfree (fstr, CIbyte *); | |
| 255 } | |
| 256 | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
257 #ifdef NEW_GC |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
258 static void |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
259 bigfloat_finalize (void *header, int for_disksave) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
260 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
261 if (!for_disksave) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
262 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
263 struct Lisp_Bigfloat *num = (struct Lisp_Bigfloat *) header; |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
264 bigfloat_fini (num->bf); |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
265 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
266 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
267 #define BIGFLOAT_FINALIZE bigfloat_finalize |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
268 #else |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
269 #define BIGFLOAT_FINALIZE 0 |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
270 #endif |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
271 |
| 1983 | 272 static int |
| 2286 | 273 bigfloat_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth)) |
| 1983 | 274 { |
| 275 return bigfloat_eql (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)); | |
| 276 } | |
| 277 | |
| 278 static Hashcode | |
| 2286 | 279 bigfloat_hash (Lisp_Object obj, int UNUSED (depth)) |
| 1983 | 280 { |
| 281 return bigfloat_hashcode (XBIGFLOAT_DATA (obj)); | |
| 282 } | |
| 283 | |
| 284 static const struct memory_description bigfloat_description[] = { | |
| 285 { XD_OPAQUE_PTR, offsetof (Lisp_Bigfloat, bf) }, | |
| 286 { XD_END } | |
| 287 }; | |
| 288 | |
| 2061 | 289 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bigfloat", bigfloat, 1, 0, |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
290 bigfloat_print, BIGFLOAT_FINALIZE, |
| 2061 | 291 bigfloat_equal, bigfloat_hash, |
| 292 bigfloat_description, Lisp_Bigfloat); | |
| 1983 | 293 |
| 2092 | 294 #endif /* HAVE_BIGFLOAT */ |
| 1983 | 295 |
| 296 Lisp_Object Qbigfloatp; | |
| 297 | |
| 298 DEFUN ("bigfloatp", Fbigfloatp, 1, 1, 0, /* | |
| 299 Return t if OBJECT is a bigfloat, nil otherwise. | |
| 300 */ | |
| 301 (object)) | |
| 302 { | |
| 303 return BIGFLOATP (object) ? Qt : Qnil; | |
| 304 } | |
| 305 | |
| 2092 | 306 DEFUN ("bigfloat-get-precision", Fbigfloat_get_precision, 1, 1, 0, /* |
| 307 Return the precision of bigfloat F as an integer. | |
| 308 */ | |
| 309 (f)) | |
| 310 { | |
| 311 CHECK_BIGFLOAT (f); | |
| 312 #ifdef HAVE_BIGNUM | |
| 313 bignum_set_ulong (scratch_bignum, XBIGFLOAT_GET_PREC (f)); | |
| 314 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
| 315 #else | |
| 316 return make_int ((int) XBIGFLOAT_GET_PREC (f)); | |
| 317 #endif | |
| 318 } | |
| 319 | |
| 320 DEFUN ("bigfloat-set-precision", Fbigfloat_set_precision, 2, 2, 0, /* | |
| 321 Set the precision of F, a bigfloat, to PRECISION, a nonnegative integer. | |
| 322 The new precision of F is returned. Note that the return value may differ | |
| 323 from PRECISION if the underlying library is unable to support exactly | |
| 324 PRECISION bits of precision. | |
| 325 */ | |
| 326 (f, precision)) | |
| 327 { | |
| 328 unsigned long prec; | |
| 329 | |
| 330 CHECK_BIGFLOAT (f); | |
| 331 if (INTP (precision)) | |
| 332 { | |
| 333 prec = (XINT (precision) <= 0) ? 1UL : (unsigned long) XINT (precision); | |
| 334 } | |
| 335 #ifdef HAVE_BIGNUM | |
| 336 else if (BIGNUMP (precision)) | |
| 337 { | |
| 338 prec = bignum_fits_ulong_p (XBIGNUM_DATA (precision)) | |
| 339 ? bignum_to_ulong (XBIGNUM_DATA (precision)) | |
| 340 : UINT_MAX; | |
| 341 } | |
| 342 #endif | |
| 343 else | |
| 344 { | |
| 345 dead_wrong_type_argument (Qintegerp, f); | |
| 346 return Qnil; | |
| 347 } | |
| 348 | |
| 349 XBIGFLOAT_SET_PREC (f, prec); | |
| 350 return Fbigfloat_get_precision (f); | |
| 351 } | |
| 352 | |
| 1983 | 353 static int |
| 2286 | 354 default_float_precision_changed (Lisp_Object UNUSED (sym), Lisp_Object *val, |
| 355 Lisp_Object UNUSED (in_object), | |
| 356 int UNUSED (flags)) | |
| 1983 | 357 { |
| 358 unsigned long prec; | |
| 359 | |
| 360 CONCHECK_INTEGER (*val); | |
| 361 #ifdef HAVE_BIGFLOAT | |
| 362 if (INTP (*val)) | |
| 363 prec = XINT (*val); | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
364 else |
| 1983 | 365 { |
| 366 if (!bignum_fits_ulong_p (XBIGNUM_DATA (*val))) | |
| 367 args_out_of_range_3 (*val, Qzero, Vbigfloat_max_prec); | |
| 368 prec = bignum_to_ulong (XBIGNUM_DATA (*val)); | |
| 369 } | |
| 370 if (prec != 0UL) | |
| 371 bigfloat_set_default_prec (prec); | |
| 372 #endif | |
| 373 return 0; | |
| 374 } | |
| 375 | |
| 376 | |
| 377 /********************************* Floating *********************************/ | |
| 378 Lisp_Object | |
| 379 make_floating (double d) | |
| 380 { | |
| 381 #ifdef HAVE_BIGFLOAT | |
| 382 if (ZEROP (Vdefault_float_precision)) | |
| 383 #endif | |
| 384 return make_float (d); | |
| 385 #ifdef HAVE_BIGFLOAT | |
| 386 else | |
| 387 return make_bigfloat (d, 0UL); | |
| 388 #endif | |
| 389 } | |
| 390 | |
| 391 DEFUN ("floatingp", Ffloatingp, 1, 1, 0, /* | |
| 392 Return t if OBJECT is a floating point number of any kind, nil otherwise. | |
| 393 */ | |
| 394 (object)) | |
| 395 { | |
| 396 return FLOATINGP (object) ? Qt : Qnil; | |
| 397 } | |
| 398 | |
| 399 | |
| 400 /********************************** Reals ***********************************/ | |
| 401 DEFUN ("realp", Frealp, 1, 1, 0, /* | |
| 402 Return t if OBJECT is a real, nil otherwise. | |
| 403 */ | |
| 404 (object)) | |
| 405 { | |
| 406 return REALP (object) ? Qt : Qnil; | |
| 407 } | |
| 408 | |
| 409 | |
| 410 /********************************* Numbers **********************************/ | |
| 411 DEFUN ("canonicalize-number", Fcanonicalize_number, 1, 1, 0, /* | |
| 412 Return the canonical form of NUMBER. | |
| 413 */ | |
| 414 (number)) | |
| 415 { | |
| 416 /* The tests should go in order from larger, more expressive, or more | |
| 417 complex types to smaller, less expressive, or simpler types so that a | |
| 418 number can cascade all the way down to the simplest type if | |
| 419 appropriate. */ | |
| 420 #ifdef HAVE_RATIO | |
| 421 if (RATIOP (number) && | |
| 422 bignum_fits_long_p (XRATIO_DENOMINATOR (number)) && | |
| 423 bignum_to_long (XRATIO_DENOMINATOR (number)) == 1L) | |
|
4883
f730384b8ddf
Be more careful about canonical integer forms when dealing with ratios.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4802
diff
changeset
|
424 number = Fcanonicalize_number (make_bignum_bg (XRATIO_NUMERATOR (number))); |
| 1983 | 425 #endif |
| 426 #ifdef HAVE_BIGNUM | |
| 3391 | 427 if (BIGNUMP (number) && bignum_fits_emacs_int_p (XBIGNUM_DATA (number))) |
| 1983 | 428 { |
| 3391 | 429 EMACS_INT n = bignum_to_emacs_int (XBIGNUM_DATA (number)); |
| 1983 | 430 if (NUMBER_FITS_IN_AN_EMACS_INT (n)) |
| 431 number = make_int (n); | |
| 432 } | |
| 433 #endif | |
| 434 return number; | |
| 435 } | |
| 436 | |
| 437 enum number_type | |
| 438 get_number_type (Lisp_Object arg) | |
| 439 { | |
| 440 if (INTP (arg)) | |
| 441 return FIXNUM_T; | |
| 442 #ifdef HAVE_BIGNUM | |
| 443 if (BIGNUMP (arg)) | |
| 444 return BIGNUM_T; | |
| 445 #endif | |
| 446 #ifdef HAVE_RATIO | |
| 447 if (RATIOP (arg)) | |
| 448 return RATIO_T; | |
| 449 #endif | |
| 450 if (FLOATP (arg)) | |
| 451 return FLOAT_T; | |
| 452 #ifdef HAVE_BIGFLOAT | |
| 453 if (BIGFLOATP (arg)) | |
| 454 return BIGFLOAT_T; | |
| 455 #endif | |
| 456 /* Catch unintentional bad uses of this function */ | |
| 2500 | 457 ABORT (); |
| 1995 | 458 /* NOTREACHED */ |
| 459 return FIXNUM_T; | |
| 1983 | 460 } |
| 461 | |
| 462 /* Convert NUMBER to type TYPE. If TYPE is BIGFLOAT_T then use the indicated | |
| 463 PRECISION; otherwise, PRECISION is ignored. */ | |
| 464 static Lisp_Object | |
| 465 internal_coerce_number (Lisp_Object number, enum number_type type, | |
| 2286 | 466 #ifdef HAVE_BIGFLOAT |
| 467 unsigned long precision | |
| 468 #else | |
| 469 unsigned long UNUSED (precision) | |
| 470 #endif | |
| 471 ) | |
| 1983 | 472 { |
| 473 enum number_type current_type; | |
| 474 | |
| 475 if (CHARP (number)) | |
| 476 number = make_int (XCHAR (number)); | |
| 477 else if (MARKERP (number)) | |
| 478 number = make_int (marker_position (number)); | |
| 479 | |
| 480 /* Note that CHECK_NUMBER ensures that NUMBER is a supported type. Hence, | |
| 2500 | 481 we ABORT() in the #else sections below, because it shouldn't be possible |
| 1983 | 482 to arrive there. */ |
| 483 CHECK_NUMBER (number); | |
| 484 current_type = get_number_type (number); | |
| 485 switch (current_type) | |
| 486 { | |
| 487 case FIXNUM_T: | |
| 488 switch (type) | |
| 489 { | |
| 490 case FIXNUM_T: | |
| 491 return number; | |
| 492 case BIGNUM_T: | |
| 493 #ifdef HAVE_BIGNUM | |
| 494 return make_bignum (XREALINT (number)); | |
| 495 #else | |
| 2500 | 496 ABORT (); |
| 1983 | 497 #endif /* HAVE_BIGNUM */ |
| 498 case RATIO_T: | |
| 499 #ifdef HAVE_RATIO | |
| 500 return make_ratio (XREALINT (number), 1UL); | |
| 501 #else | |
| 2500 | 502 ABORT (); |
| 1983 | 503 #endif /* HAVE_RATIO */ |
| 504 case FLOAT_T: | |
| 505 return make_float (XREALINT (number)); | |
| 506 case BIGFLOAT_T: | |
| 507 #ifdef HAVE_BIGFLOAT | |
| 508 return make_bigfloat (XREALINT (number), precision); | |
| 509 #else | |
| 2500 | 510 ABORT (); |
| 1983 | 511 #endif /* HAVE_BIGFLOAT */ |
| 512 } | |
| 513 case BIGNUM_T: | |
| 514 #ifdef HAVE_BIGNUM | |
| 515 switch (type) | |
| 516 { | |
| 517 case FIXNUM_T: | |
| 518 return make_int (bignum_to_long (XBIGNUM_DATA (number))); | |
| 519 case BIGNUM_T: | |
| 520 return number; | |
| 521 case RATIO_T: | |
| 522 #ifdef HAVE_RATIO | |
| 523 bignum_set_long (scratch_bignum, 1L); | |
| 524 return make_ratio_bg (XBIGNUM_DATA (number), scratch_bignum); | |
| 525 #else | |
| 2500 | 526 ABORT (); |
| 1983 | 527 #endif /* HAVE_RATIO */ |
| 528 case FLOAT_T: | |
| 529 return make_float (bignum_to_double (XBIGNUM_DATA (number))); | |
| 530 case BIGFLOAT_T: | |
| 531 #ifdef HAVE_BIGFLOAT | |
| 532 { | |
| 533 Lisp_Object temp; | |
| 534 temp = make_bigfloat (0.0, precision); | |
| 535 bigfloat_set_bignum (XBIGFLOAT_DATA (temp), XBIGNUM_DATA (number)); | |
| 536 return temp; | |
| 537 } | |
| 538 #else | |
| 2500 | 539 ABORT (); |
| 1983 | 540 #endif /* HAVE_BIGFLOAT */ |
| 541 } | |
| 542 #else | |
| 2500 | 543 ABORT (); |
| 1983 | 544 #endif /* HAVE_BIGNUM */ |
| 545 case RATIO_T: | |
| 546 #ifdef HAVE_RATIO | |
| 547 switch (type) | |
| 548 { | |
| 549 case FIXNUM_T: | |
| 550 bignum_div (scratch_bignum, XRATIO_NUMERATOR (number), | |
| 551 XRATIO_DENOMINATOR (number)); | |
| 552 return make_int (bignum_to_long (scratch_bignum)); | |
| 553 case BIGNUM_T: | |
| 554 bignum_div (scratch_bignum, XRATIO_NUMERATOR (number), | |
| 555 XRATIO_DENOMINATOR (number)); | |
| 556 return make_bignum_bg (scratch_bignum); | |
| 557 case RATIO_T: | |
| 558 return number; | |
| 559 case FLOAT_T: | |
| 560 return make_float (ratio_to_double (XRATIO_DATA (number))); | |
| 561 case BIGFLOAT_T: | |
| 562 #ifdef HAVE_BIGFLOAT | |
| 563 { | |
| 564 Lisp_Object temp; | |
| 565 temp = make_bigfloat (0.0, precision); | |
| 566 bigfloat_set_ratio (XBIGFLOAT_DATA (temp), XRATIO_DATA (number)); | |
| 567 return temp; | |
| 568 } | |
| 569 #else | |
| 2500 | 570 ABORT (); |
| 1983 | 571 #endif /* HAVE_BIGFLOAT */ |
| 572 } | |
| 573 #else | |
| 2500 | 574 ABORT (); |
| 1983 | 575 #endif /* HAVE_RATIO */ |
| 576 case FLOAT_T: | |
| 577 switch (type) | |
| 578 { | |
| 579 case FIXNUM_T: | |
|
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3391
diff
changeset
|
580 return Ftruncate (number, Qnil); |
| 1983 | 581 case BIGNUM_T: |
| 582 #ifdef HAVE_BIGNUM | |
| 583 bignum_set_double (scratch_bignum, XFLOAT_DATA (number)); | |
| 584 return make_bignum_bg (scratch_bignum); | |
| 585 #else | |
| 2500 | 586 ABORT (); |
| 1983 | 587 #endif /* HAVE_BIGNUM */ |
| 588 case RATIO_T: | |
| 589 #ifdef HAVE_RATIO | |
| 590 ratio_set_double (scratch_ratio, XFLOAT_DATA (number)); | |
| 591 return make_ratio_rt (scratch_ratio); | |
| 592 #else | |
| 2500 | 593 ABORT (); |
| 1983 | 594 #endif /* HAVE_RATIO */ |
| 595 case FLOAT_T: | |
| 596 return number; | |
| 597 case BIGFLOAT_T: | |
| 598 #ifdef HAVE_BIGFLOAT | |
| 599 bigfloat_set_prec (scratch_bigfloat, precision); | |
| 600 bigfloat_set_double (scratch_bigfloat, XFLOAT_DATA (number)); | |
| 601 return make_bigfloat_bf (scratch_bigfloat); | |
| 602 #else | |
| 2500 | 603 ABORT (); |
| 1983 | 604 #endif /* HAVE_BIGFLOAT */ |
| 605 } | |
| 606 case BIGFLOAT_T: | |
| 607 #ifdef HAVE_BIGFLOAT | |
| 608 switch (type) | |
| 609 { | |
| 610 case FIXNUM_T: | |
| 611 return make_int (bigfloat_to_long (XBIGFLOAT_DATA (number))); | |
| 612 case BIGNUM_T: | |
| 613 #ifdef HAVE_BIGNUM | |
| 614 bignum_set_bigfloat (scratch_bignum, XBIGFLOAT_DATA (number)); | |
| 615 return make_bignum_bg (scratch_bignum); | |
| 616 #else | |
| 2500 | 617 ABORT (); |
| 1983 | 618 #endif /* HAVE_BIGNUM */ |
| 619 case RATIO_T: | |
| 620 #ifdef HAVE_RATIO | |
| 621 ratio_set_bigfloat (scratch_ratio, XBIGFLOAT_DATA (number)); | |
| 622 return make_ratio_rt (scratch_ratio); | |
| 623 #else | |
| 2500 | 624 ABORT (); |
| 1983 | 625 #endif |
| 626 case FLOAT_T: | |
| 627 return make_float (bigfloat_to_double (XBIGFLOAT_DATA (number))); | |
| 628 case BIGFLOAT_T: | |
| 629 /* FIXME: Do we need to change the precision? */ | |
| 630 return number; | |
| 631 } | |
| 632 #else | |
| 2500 | 633 ABORT (); |
| 1983 | 634 #endif /* HAVE_BIGFLOAT */ |
| 635 } | |
| 2500 | 636 ABORT (); |
| 1995 | 637 /* NOTREACHED */ |
| 638 return Qzero; | |
| 1983 | 639 } |
| 640 | |
| 641 /* This function promotes its arguments as necessary to make them both the | |
| 642 same type. It destructively modifies its arguments to do so. Characters | |
| 643 and markers are ALWAYS converted to integers. */ | |
| 644 enum number_type | |
| 645 promote_args (Lisp_Object *arg1, Lisp_Object *arg2) | |
| 646 { | |
| 647 enum number_type type1, type2; | |
| 648 | |
| 649 if (CHARP (*arg1)) | |
| 650 *arg1 = make_int (XCHAR (*arg1)); | |
| 651 else if (MARKERP (*arg1)) | |
| 652 *arg1 = make_int (marker_position (*arg1)); | |
| 653 if (CHARP (*arg2)) | |
| 654 *arg2 = make_int (XCHAR (*arg2)); | |
| 655 else if (MARKERP (*arg2)) | |
| 656 *arg2 = make_int (marker_position (*arg2)); | |
| 657 | |
| 658 CHECK_NUMBER (*arg1); | |
| 659 CHECK_NUMBER (*arg2); | |
| 660 | |
| 661 type1 = get_number_type (*arg1); | |
| 662 type2 = get_number_type (*arg2); | |
| 663 | |
| 664 if (type1 < type2) | |
| 665 { | |
| 666 *arg1 = internal_coerce_number (*arg1, type2, | |
| 667 #ifdef HAVE_BIGFLOAT | |
| 668 type2 == BIGFLOAT_T | |
| 669 ? XBIGFLOAT_GET_PREC (*arg2) : | |
| 670 #endif | |
| 671 0UL); | |
| 672 return type2; | |
| 673 } | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
674 |
| 1983 | 675 if (type2 < type1) |
| 676 { | |
| 677 *arg2 = internal_coerce_number (*arg2, type1, | |
| 678 #ifdef HAVE_BIGFLOAT | |
| 679 type1 == BIGFLOAT_T | |
| 680 ? XBIGFLOAT_GET_PREC (*arg1) : | |
| 681 #endif | |
| 682 0UL); | |
| 683 return type1; | |
| 684 } | |
| 685 | |
| 686 /* No conversion necessary */ | |
| 687 return type1; | |
| 688 } | |
| 689 | |
| 690 DEFUN ("coerce-number", Fcoerce_number, 2, 3, 0, /* | |
| 691 Convert NUMBER to the indicated type, possibly losing information. | |
| 692 Do not call this function. Use `coerce' instead. | |
| 693 | |
| 3025 | 694 TYPE is one of the symbols `fixnum', `integer', `ratio', `float', or |
| 695 `bigfloat'. Not all of these types may be supported. | |
| 1983 | 696 |
| 697 PRECISION is the number of bits of precision to use when converting to | |
| 698 bigfloat; it is ignored otherwise. If nil, the default precision is used. | |
| 699 | |
| 700 Note that some conversions lose information. No error is signaled in such | |
| 701 cases; the information is silently lost. | |
| 702 */ | |
| 2595 | 703 (number, type, USED_IF_BIGFLOAT (precision))) |
| 1983 | 704 { |
| 705 CHECK_SYMBOL (type); | |
| 706 if (EQ (type, Qfixnum)) | |
| 707 return internal_coerce_number (number, FIXNUM_T, 0UL); | |
| 708 else if (EQ (type, Qinteger)) | |
| 709 { | |
| 710 /* If bignums are available, we always convert to one first, then | |
| 711 downgrade to a fixnum if possible. */ | |
| 712 #ifdef HAVE_BIGNUM | |
| 713 return Fcanonicalize_number | |
| 714 (internal_coerce_number (number, BIGNUM_T, 0UL)); | |
| 715 #else | |
| 716 return internal_coerce_number (number, FIXNUM_T, 0UL); | |
| 717 #endif | |
| 718 } | |
| 719 #ifdef HAVE_RATIO | |
| 720 else if (EQ (type, Qratio)) | |
| 721 return internal_coerce_number (number, RATIO_T, 0UL); | |
| 722 #endif | |
| 723 else if (EQ (type, Qfloat)) | |
| 724 return internal_coerce_number (number, FLOAT_T, 0UL); | |
| 725 #ifdef HAVE_BIGFLOAT | |
| 726 else if (EQ (type, Qbigfloat)) | |
| 727 { | |
| 728 unsigned long prec; | |
| 729 | |
| 730 if (NILP (precision)) | |
| 731 prec = bigfloat_get_default_prec (); | |
| 732 else | |
| 733 { | |
| 734 CHECK_INTEGER (precision); | |
| 735 #ifdef HAVE_BIGNUM | |
| 736 if (INTP (precision)) | |
| 737 #endif /* HAVE_BIGNUM */ | |
| 738 prec = (unsigned long) XREALINT (precision); | |
| 739 #ifdef HAVE_BIGNUM | |
| 740 else | |
| 741 { | |
| 742 if (!bignum_fits_ulong_p (XBIGNUM_DATA (precision))) | |
| 743 args_out_of_range (precision, Vbigfloat_max_prec); | |
| 744 prec = bignum_to_ulong (XBIGNUM_DATA (precision)); | |
| 745 } | |
| 746 #endif /* HAVE_BIGNUM */ | |
| 747 } | |
| 748 return internal_coerce_number (number, BIGFLOAT_T, prec); | |
| 749 } | |
| 750 #endif /* HAVE_BIGFLOAT */ | |
| 751 | |
| 752 Fsignal (Qunsupported_type, type); | |
| 753 /* NOTREACHED */ | |
| 754 return Qnil; | |
| 755 } | |
| 756 | |
| 757 | |
| 758 void | |
| 759 syms_of_number (void) | |
| 760 { | |
| 761 #ifdef HAVE_BIGNUM | |
| 762 INIT_LRECORD_IMPLEMENTATION (bignum); | |
| 763 #endif | |
| 764 #ifdef HAVE_RATIO | |
| 765 INIT_LRECORD_IMPLEMENTATION (ratio); | |
| 766 #endif | |
| 767 #ifdef HAVE_BIGFLOAT | |
| 768 INIT_LRECORD_IMPLEMENTATION (bigfloat); | |
| 769 #endif | |
| 770 | |
| 771 /* Type predicates */ | |
| 772 DEFSYMBOL (Qrationalp); | |
| 773 DEFSYMBOL (Qfloatingp); | |
| 774 DEFSYMBOL (Qrealp); | |
| 775 DEFSYMBOL (Qbignump); | |
| 776 DEFSYMBOL (Qratiop); | |
| 777 DEFSYMBOL (Qbigfloatp); | |
| 778 | |
| 779 /* Functions */ | |
| 780 DEFSUBR (Fbignump); | |
| 781 DEFSUBR (Fratiop); | |
| 782 DEFSUBR (Frationalp); | |
| 783 DEFSUBR (Fnumerator); | |
| 784 DEFSUBR (Fdenominator); | |
| 785 DEFSUBR (Fbigfloatp); | |
| 2092 | 786 DEFSUBR (Fbigfloat_get_precision); |
| 787 DEFSUBR (Fbigfloat_set_precision); | |
| 2001 | 788 DEFSUBR (Ffloatingp); |
| 1983 | 789 DEFSUBR (Frealp); |
| 790 DEFSUBR (Fcanonicalize_number); | |
| 791 DEFSUBR (Fcoerce_number); | |
| 792 | |
| 793 /* Errors */ | |
| 794 DEFERROR_STANDARD (Qunsupported_type, Qwrong_type_argument); | |
| 795 } | |
| 796 | |
| 797 void | |
| 798 vars_of_number (void) | |
| 799 { | |
| 2051 | 800 /* These variables are Lisp variables rather than number variables so that |
| 801 we can put bignums in them. */ | |
| 1983 | 802 DEFVAR_LISP_MAGIC ("default-float-precision", &Vdefault_float_precision, /* |
| 803 The default floating-point precision for newly created floating point values. | |
| 2092 | 804 This should be 0 to create Lisp float types, or an unsigned integer no greater |
| 805 than `bigfloat-maximum-precision' to create Lisp bigfloat types with the | |
| 806 indicated precision. | |
| 1983 | 807 */ default_float_precision_changed); |
| 808 Vdefault_float_precision = make_int (0); | |
| 809 | |
| 2092 | 810 DEFVAR_CONST_LISP ("bigfloat-maximum-precision", &Vbigfloat_max_prec /* |
| 1983 | 811 The maximum number of bits of precision a bigfloat can have. |
| 2092 | 812 This is determined by the underlying library used to implement bigfloats. |
| 1983 | 813 */); |
| 814 | |
| 2061 | 815 #ifdef HAVE_BIGFLOAT |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
816 /* Don't create a bignum here. Otherwise, we lose with NEW_GC + pdump. |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
817 See reinit_vars_of_number(). */ |
| 2061 | 818 Vbigfloat_max_prec = make_int (EMACS_INT_MAX); |
| 819 #else | |
| 2051 | 820 Vbigfloat_max_prec = make_int (0); |
| 821 #endif /* HAVE_BIGFLOAT */ | |
| 822 | |
| 1983 | 823 Fprovide (intern ("number-types")); |
| 824 #ifdef HAVE_BIGNUM | |
| 825 Fprovide (intern ("bignum")); | |
| 826 #endif | |
| 827 #ifdef HAVE_RATIO | |
| 828 Fprovide (intern ("ratio")); | |
| 829 #endif | |
| 830 #ifdef HAVE_BIGFLOAT | |
| 831 Fprovide (intern ("bigfloat")); | |
| 832 #endif | |
| 833 } | |
| 834 | |
| 835 void | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
836 reinit_vars_of_number (void) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
837 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
838 #if defined(HAVE_BIGFLOAT) && defined(HAVE_BIGNUM) |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
839 Vbigfloat_max_prec = make_bignum (0L); |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
840 bignum_set_ulong (XBIGNUM_DATA (Vbigfloat_max_prec), ULONG_MAX); |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
841 #endif |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
842 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
843 |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
844 void |
| 1983 | 845 init_number (void) |
| 846 { | |
| 847 if (!number_initialized) | |
| 848 { | |
| 849 number_initialized = 1; | |
| 850 | |
| 851 #ifdef WITH_GMP | |
| 852 init_number_gmp (); | |
| 853 #endif | |
| 854 #ifdef WITH_MP | |
| 855 init_number_mp (); | |
| 856 #endif | |
| 857 | |
| 858 #ifdef HAVE_BIGNUM | |
| 859 bignum_init (scratch_bignum); | |
| 860 bignum_init (scratch_bignum2); | |
| 861 #endif | |
| 862 | |
| 863 #ifdef HAVE_RATIO | |
| 864 ratio_init (scratch_ratio); | |
|
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3391
diff
changeset
|
865 ratio_init (scratch_ratio2); |
| 1983 | 866 #endif |
| 867 | |
| 868 #ifdef HAVE_BIGFLOAT | |
| 869 bigfloat_init (scratch_bigfloat); | |
| 870 bigfloat_init (scratch_bigfloat2); | |
| 871 #endif | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
872 |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
873 #ifndef PDUMP |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
874 reinit_vars_of_number (); |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
875 #endif |
| 1983 | 876 } |
| 877 } |
