Mercurial > hg > xemacs-beta
annotate src/number.c @ 4820:e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
lisp/ChangeLog addition:
2010-01-09 Aidan Kehoe <kehoea@parhasard.net>
* descr-text.el (describe-char-unihan-field-descriptions):
* cl-macs.el:
Use keywords, not ordinary symbols, in the hash table read syntax,
for compatibility with Common Lisp and recent GNU Emacs.
man/ChangeLog addition:
2010-01-09 Aidan Kehoe <kehoea@parhasard.net>
* lispref/objects.texi (Hash Table Type):
* lispref/hash-tables.texi (Introduction to Hash Tables):
Use keywords, not ordinary symbols, in the hash table read syntax;
document that we do accept the ordinary symbols for the sake of
backward-compatiblity.
2010-01-09 Aidan Kehoe <kehoea@parhasard.net>
* elhash.c:
(print_hash_table, print_hash_table_data)
(hash_table_instantiate)
(structure_type_create_hash_table_structure_name):
(syms_of_elhash):
Use keywords, not ordinary symbols, in the hash table read syntax,
for compatibility with Common Lisp and recent GNU Emacs. Accept
the non-keyword syntax, but don't allow mixing of the two styles.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 09 Jan 2010 17:28:51 +0000 |
| parents | 2fc0e2f18322 |
| children | f730384b8ddf 6772ce4d982b |
| 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; |
| 35 Fixnum Vmost_negative_fixnum, Vmost_positive_fixnum; | |
| 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 /********************************* Integers *********************************/ | |
| 143 DEFUN ("integerp", Fintegerp, 1, 1, 0, /* | |
| 144 Return t if OBJECT is an integer, nil otherwise. | |
| 145 */ | |
| 146 (object)) | |
| 147 { | |
| 148 return INTEGERP (object) ? Qt : Qnil; | |
| 149 } | |
| 150 | |
| 151 DEFUN ("evenp", Fevenp, 1, 1, 0, /* | |
| 152 Return t if INTEGER is even, nil otherwise. | |
| 153 */ | |
| 154 (integer)) | |
| 155 { | |
| 156 CONCHECK_INTEGER (integer); | |
| 1996 | 157 return (BIGNUMP (integer) |
| 158 ? bignum_evenp (XBIGNUM_DATA (integer)) | |
| 159 : XTYPE (integer) == Lisp_Type_Int_Even) ? Qt : Qnil; | |
| 1983 | 160 } |
| 161 | |
| 2019 | 162 DEFUN ("oddp", Foddp, 1, 1, 0, /* |
| 1983 | 163 Return t if INTEGER is odd, nil otherwise. |
| 164 */ | |
| 165 (integer)) | |
| 166 { | |
| 167 CONCHECK_INTEGER (integer); | |
| 1996 | 168 return (BIGNUMP (integer) |
| 169 ? bignum_oddp (XBIGNUM_DATA (integer)) | |
| 170 : XTYPE (integer) == Lisp_Type_Int_Odd) ? Qt : Qnil; | |
| 1983 | 171 } |
| 172 | |
| 173 | |
| 174 /********************************** Ratios **********************************/ | |
| 175 #ifdef HAVE_RATIO | |
| 176 static void | |
| 2286 | 177 ratio_print (Lisp_Object obj, Lisp_Object printcharfun, |
| 178 int UNUSED (escapeflag)) | |
| 1983 | 179 { |
| 180 CIbyte *rstr = ratio_to_string (XRATIO_DATA (obj), 10); | |
| 181 write_c_string (printcharfun, rstr); | |
| 182 xfree (rstr, CIbyte *); | |
| 183 } | |
| 184 | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
185 #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
|
186 static void |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
187 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
|
188 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
189 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
|
190 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
191 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
|
192 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
|
193 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
194 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
195 #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
|
196 #else |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
197 #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
|
198 #endif |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
199 |
| 1983 | 200 static int |
| 2286 | 201 ratio_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth)) |
| 1983 | 202 { |
| 203 return ratio_eql (XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
| 204 } | |
| 205 | |
| 206 static Hashcode | |
| 2286 | 207 ratio_hash (Lisp_Object obj, int UNUSED (depth)) |
| 1983 | 208 { |
| 209 return ratio_hashcode (XRATIO_DATA (obj)); | |
| 210 } | |
| 211 | |
| 212 static const struct memory_description ratio_description[] = { | |
| 213 { XD_OPAQUE_PTR, offsetof (Lisp_Ratio, data) }, | |
| 214 { XD_END } | |
| 215 }; | |
| 216 | |
| 2061 | 217 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
|
218 RATIO_FINALIZE, ratio_equal, ratio_hash, |
| 2061 | 219 ratio_description, Lisp_Ratio); |
| 1983 | 220 |
| 2092 | 221 #endif /* HAVE_RATIO */ |
| 1983 | 222 |
| 223 Lisp_Object Qratiop; | |
| 224 | |
| 225 DEFUN ("ratiop", Fratiop, 1, 1, 0, /* | |
| 226 Return t if OBJECT is a ratio, nil otherwise. | |
| 227 */ | |
| 228 (object)) | |
| 229 { | |
| 230 return RATIOP (object) ? Qt : Qnil; | |
| 231 } | |
| 232 | |
| 233 | |
| 234 /******************************** Rationals *********************************/ | |
| 235 DEFUN ("rationalp", Frationalp, 1, 1, 0, /* | |
| 236 Return t if OBJECT is a rational, nil otherwise. | |
| 237 */ | |
| 238 (object)) | |
| 239 { | |
| 240 return RATIONALP (object) ? Qt : Qnil; | |
| 241 } | |
| 242 | |
| 243 DEFUN ("numerator", Fnumerator, 1, 1, 0, /* | |
| 244 Return the numerator of the canonical form of RATIONAL. | |
| 245 If RATIONAL is an integer, RATIONAL is returned. | |
| 246 */ | |
| 247 (rational)) | |
| 248 { | |
| 249 CONCHECK_RATIONAL (rational); | |
| 250 #ifdef HAVE_RATIO | |
| 251 return RATIOP (rational) | |
| 252 ? make_bignum_bg (XRATIO_NUMERATOR (rational)) | |
| 253 : rational; | |
| 254 #else | |
| 255 return rational; | |
| 256 #endif | |
| 257 } | |
| 258 | |
| 259 DEFUN ("denominator", Fdenominator, 1, 1, 0, /* | |
| 260 Return the denominator of the canonical form of RATIONAL. | |
| 261 If RATIONAL is an integer, 1 is returned. | |
| 262 */ | |
| 263 (rational)) | |
| 264 { | |
| 265 CONCHECK_RATIONAL (rational); | |
| 266 #ifdef HAVE_RATIO | |
| 267 return RATIOP (rational) | |
| 268 ? make_bignum_bg (XRATIO_DENOMINATOR (rational)) | |
| 269 : make_int (1); | |
| 270 #else | |
| 271 return rational; | |
| 272 #endif | |
| 273 } | |
| 274 | |
| 275 | |
| 276 /******************************** Bigfloats *********************************/ | |
| 277 #ifdef HAVE_BIGFLOAT | |
| 278 static void | |
| 2286 | 279 bigfloat_print (Lisp_Object obj, Lisp_Object printcharfun, |
| 280 int UNUSED (escapeflag)) | |
| 1983 | 281 { |
| 282 CIbyte *fstr = bigfloat_to_string (XBIGFLOAT_DATA (obj), 10); | |
| 283 write_c_string (printcharfun, fstr); | |
| 284 xfree (fstr, CIbyte *); | |
| 285 } | |
| 286 | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
287 #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
|
288 static void |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
289 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
|
290 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
291 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
|
292 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
293 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
|
294 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
|
295 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
296 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
297 #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
|
298 #else |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
299 #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
|
300 #endif |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
301 |
| 1983 | 302 static int |
| 2286 | 303 bigfloat_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth)) |
| 1983 | 304 { |
| 305 return bigfloat_eql (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)); | |
| 306 } | |
| 307 | |
| 308 static Hashcode | |
| 2286 | 309 bigfloat_hash (Lisp_Object obj, int UNUSED (depth)) |
| 1983 | 310 { |
| 311 return bigfloat_hashcode (XBIGFLOAT_DATA (obj)); | |
| 312 } | |
| 313 | |
| 314 static const struct memory_description bigfloat_description[] = { | |
| 315 { XD_OPAQUE_PTR, offsetof (Lisp_Bigfloat, bf) }, | |
| 316 { XD_END } | |
| 317 }; | |
| 318 | |
| 2061 | 319 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
|
320 bigfloat_print, BIGFLOAT_FINALIZE, |
| 2061 | 321 bigfloat_equal, bigfloat_hash, |
| 322 bigfloat_description, Lisp_Bigfloat); | |
| 1983 | 323 |
| 2092 | 324 #endif /* HAVE_BIGFLOAT */ |
| 1983 | 325 |
| 326 Lisp_Object Qbigfloatp; | |
| 327 | |
| 328 DEFUN ("bigfloatp", Fbigfloatp, 1, 1, 0, /* | |
| 329 Return t if OBJECT is a bigfloat, nil otherwise. | |
| 330 */ | |
| 331 (object)) | |
| 332 { | |
| 333 return BIGFLOATP (object) ? Qt : Qnil; | |
| 334 } | |
| 335 | |
| 2092 | 336 DEFUN ("bigfloat-get-precision", Fbigfloat_get_precision, 1, 1, 0, /* |
| 337 Return the precision of bigfloat F as an integer. | |
| 338 */ | |
| 339 (f)) | |
| 340 { | |
| 341 CHECK_BIGFLOAT (f); | |
| 342 #ifdef HAVE_BIGNUM | |
| 343 bignum_set_ulong (scratch_bignum, XBIGFLOAT_GET_PREC (f)); | |
| 344 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
| 345 #else | |
| 346 return make_int ((int) XBIGFLOAT_GET_PREC (f)); | |
| 347 #endif | |
| 348 } | |
| 349 | |
| 350 DEFUN ("bigfloat-set-precision", Fbigfloat_set_precision, 2, 2, 0, /* | |
| 351 Set the precision of F, a bigfloat, to PRECISION, a nonnegative integer. | |
| 352 The new precision of F is returned. Note that the return value may differ | |
| 353 from PRECISION if the underlying library is unable to support exactly | |
| 354 PRECISION bits of precision. | |
| 355 */ | |
| 356 (f, precision)) | |
| 357 { | |
| 358 unsigned long prec; | |
| 359 | |
| 360 CHECK_BIGFLOAT (f); | |
| 361 if (INTP (precision)) | |
| 362 { | |
| 363 prec = (XINT (precision) <= 0) ? 1UL : (unsigned long) XINT (precision); | |
| 364 } | |
| 365 #ifdef HAVE_BIGNUM | |
| 366 else if (BIGNUMP (precision)) | |
| 367 { | |
| 368 prec = bignum_fits_ulong_p (XBIGNUM_DATA (precision)) | |
| 369 ? bignum_to_ulong (XBIGNUM_DATA (precision)) | |
| 370 : UINT_MAX; | |
| 371 } | |
| 372 #endif | |
| 373 else | |
| 374 { | |
| 375 dead_wrong_type_argument (Qintegerp, f); | |
| 376 return Qnil; | |
| 377 } | |
| 378 | |
| 379 XBIGFLOAT_SET_PREC (f, prec); | |
| 380 return Fbigfloat_get_precision (f); | |
| 381 } | |
| 382 | |
| 1983 | 383 static int |
| 2286 | 384 default_float_precision_changed (Lisp_Object UNUSED (sym), Lisp_Object *val, |
| 385 Lisp_Object UNUSED (in_object), | |
| 386 int UNUSED (flags)) | |
| 1983 | 387 { |
| 388 unsigned long prec; | |
| 389 | |
| 390 CONCHECK_INTEGER (*val); | |
| 391 #ifdef HAVE_BIGFLOAT | |
| 392 if (INTP (*val)) | |
| 393 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
|
394 else |
| 1983 | 395 { |
| 396 if (!bignum_fits_ulong_p (XBIGNUM_DATA (*val))) | |
| 397 args_out_of_range_3 (*val, Qzero, Vbigfloat_max_prec); | |
| 398 prec = bignum_to_ulong (XBIGNUM_DATA (*val)); | |
| 399 } | |
| 400 if (prec != 0UL) | |
| 401 bigfloat_set_default_prec (prec); | |
| 402 #endif | |
| 403 return 0; | |
| 404 } | |
| 405 | |
| 406 | |
| 407 /********************************* Floating *********************************/ | |
| 408 Lisp_Object | |
| 409 make_floating (double d) | |
| 410 { | |
| 411 #ifdef HAVE_BIGFLOAT | |
| 412 if (ZEROP (Vdefault_float_precision)) | |
| 413 #endif | |
| 414 return make_float (d); | |
| 415 #ifdef HAVE_BIGFLOAT | |
| 416 else | |
| 417 return make_bigfloat (d, 0UL); | |
| 418 #endif | |
| 419 } | |
| 420 | |
| 421 DEFUN ("floatingp", Ffloatingp, 1, 1, 0, /* | |
| 422 Return t if OBJECT is a floating point number of any kind, nil otherwise. | |
| 423 */ | |
| 424 (object)) | |
| 425 { | |
| 426 return FLOATINGP (object) ? Qt : Qnil; | |
| 427 } | |
| 428 | |
| 429 | |
| 430 /********************************** Reals ***********************************/ | |
| 431 DEFUN ("realp", Frealp, 1, 1, 0, /* | |
| 432 Return t if OBJECT is a real, nil otherwise. | |
| 433 */ | |
| 434 (object)) | |
| 435 { | |
| 436 return REALP (object) ? Qt : Qnil; | |
| 437 } | |
| 438 | |
| 439 | |
| 440 /********************************* Numbers **********************************/ | |
| 441 DEFUN ("canonicalize-number", Fcanonicalize_number, 1, 1, 0, /* | |
| 442 Return the canonical form of NUMBER. | |
| 443 */ | |
| 444 (number)) | |
| 445 { | |
| 446 /* The tests should go in order from larger, more expressive, or more | |
| 447 complex types to smaller, less expressive, or simpler types so that a | |
| 448 number can cascade all the way down to the simplest type if | |
| 449 appropriate. */ | |
| 450 #ifdef HAVE_RATIO | |
| 451 if (RATIOP (number) && | |
| 452 bignum_fits_long_p (XRATIO_DENOMINATOR (number)) && | |
| 453 bignum_to_long (XRATIO_DENOMINATOR (number)) == 1L) | |
| 454 number = make_bignum_bg (XRATIO_NUMERATOR (number)); | |
| 455 #endif | |
| 456 #ifdef HAVE_BIGNUM | |
| 3391 | 457 if (BIGNUMP (number) && bignum_fits_emacs_int_p (XBIGNUM_DATA (number))) |
| 1983 | 458 { |
| 3391 | 459 EMACS_INT n = bignum_to_emacs_int (XBIGNUM_DATA (number)); |
| 1983 | 460 if (NUMBER_FITS_IN_AN_EMACS_INT (n)) |
| 461 number = make_int (n); | |
| 462 } | |
| 463 #endif | |
| 464 return number; | |
| 465 } | |
| 466 | |
| 467 enum number_type | |
| 468 get_number_type (Lisp_Object arg) | |
| 469 { | |
| 470 if (INTP (arg)) | |
| 471 return FIXNUM_T; | |
| 472 #ifdef HAVE_BIGNUM | |
| 473 if (BIGNUMP (arg)) | |
| 474 return BIGNUM_T; | |
| 475 #endif | |
| 476 #ifdef HAVE_RATIO | |
| 477 if (RATIOP (arg)) | |
| 478 return RATIO_T; | |
| 479 #endif | |
| 480 if (FLOATP (arg)) | |
| 481 return FLOAT_T; | |
| 482 #ifdef HAVE_BIGFLOAT | |
| 483 if (BIGFLOATP (arg)) | |
| 484 return BIGFLOAT_T; | |
| 485 #endif | |
| 486 /* Catch unintentional bad uses of this function */ | |
| 2500 | 487 ABORT (); |
| 1995 | 488 /* NOTREACHED */ |
| 489 return FIXNUM_T; | |
| 1983 | 490 } |
| 491 | |
| 492 /* Convert NUMBER to type TYPE. If TYPE is BIGFLOAT_T then use the indicated | |
| 493 PRECISION; otherwise, PRECISION is ignored. */ | |
| 494 static Lisp_Object | |
| 495 internal_coerce_number (Lisp_Object number, enum number_type type, | |
| 2286 | 496 #ifdef HAVE_BIGFLOAT |
| 497 unsigned long precision | |
| 498 #else | |
| 499 unsigned long UNUSED (precision) | |
| 500 #endif | |
| 501 ) | |
| 1983 | 502 { |
| 503 enum number_type current_type; | |
| 504 | |
| 505 if (CHARP (number)) | |
| 506 number = make_int (XCHAR (number)); | |
| 507 else if (MARKERP (number)) | |
| 508 number = make_int (marker_position (number)); | |
| 509 | |
| 510 /* Note that CHECK_NUMBER ensures that NUMBER is a supported type. Hence, | |
| 2500 | 511 we ABORT() in the #else sections below, because it shouldn't be possible |
| 1983 | 512 to arrive there. */ |
| 513 CHECK_NUMBER (number); | |
| 514 current_type = get_number_type (number); | |
| 515 switch (current_type) | |
| 516 { | |
| 517 case FIXNUM_T: | |
| 518 switch (type) | |
| 519 { | |
| 520 case FIXNUM_T: | |
| 521 return number; | |
| 522 case BIGNUM_T: | |
| 523 #ifdef HAVE_BIGNUM | |
| 524 return make_bignum (XREALINT (number)); | |
| 525 #else | |
| 2500 | 526 ABORT (); |
| 1983 | 527 #endif /* HAVE_BIGNUM */ |
| 528 case RATIO_T: | |
| 529 #ifdef HAVE_RATIO | |
| 530 return make_ratio (XREALINT (number), 1UL); | |
| 531 #else | |
| 2500 | 532 ABORT (); |
| 1983 | 533 #endif /* HAVE_RATIO */ |
| 534 case FLOAT_T: | |
| 535 return make_float (XREALINT (number)); | |
| 536 case BIGFLOAT_T: | |
| 537 #ifdef HAVE_BIGFLOAT | |
| 538 return make_bigfloat (XREALINT (number), precision); | |
| 539 #else | |
| 2500 | 540 ABORT (); |
| 1983 | 541 #endif /* HAVE_BIGFLOAT */ |
| 542 } | |
| 543 case BIGNUM_T: | |
| 544 #ifdef HAVE_BIGNUM | |
| 545 switch (type) | |
| 546 { | |
| 547 case FIXNUM_T: | |
| 548 return make_int (bignum_to_long (XBIGNUM_DATA (number))); | |
| 549 case BIGNUM_T: | |
| 550 return number; | |
| 551 case RATIO_T: | |
| 552 #ifdef HAVE_RATIO | |
| 553 bignum_set_long (scratch_bignum, 1L); | |
| 554 return make_ratio_bg (XBIGNUM_DATA (number), scratch_bignum); | |
| 555 #else | |
| 2500 | 556 ABORT (); |
| 1983 | 557 #endif /* HAVE_RATIO */ |
| 558 case FLOAT_T: | |
| 559 return make_float (bignum_to_double (XBIGNUM_DATA (number))); | |
| 560 case BIGFLOAT_T: | |
| 561 #ifdef HAVE_BIGFLOAT | |
| 562 { | |
| 563 Lisp_Object temp; | |
| 564 temp = make_bigfloat (0.0, precision); | |
| 565 bigfloat_set_bignum (XBIGFLOAT_DATA (temp), XBIGNUM_DATA (number)); | |
| 566 return temp; | |
| 567 } | |
| 568 #else | |
| 2500 | 569 ABORT (); |
| 1983 | 570 #endif /* HAVE_BIGFLOAT */ |
| 571 } | |
| 572 #else | |
| 2500 | 573 ABORT (); |
| 1983 | 574 #endif /* HAVE_BIGNUM */ |
| 575 case RATIO_T: | |
| 576 #ifdef HAVE_RATIO | |
| 577 switch (type) | |
| 578 { | |
| 579 case FIXNUM_T: | |
| 580 bignum_div (scratch_bignum, XRATIO_NUMERATOR (number), | |
| 581 XRATIO_DENOMINATOR (number)); | |
| 582 return make_int (bignum_to_long (scratch_bignum)); | |
| 583 case BIGNUM_T: | |
| 584 bignum_div (scratch_bignum, XRATIO_NUMERATOR (number), | |
| 585 XRATIO_DENOMINATOR (number)); | |
| 586 return make_bignum_bg (scratch_bignum); | |
| 587 case RATIO_T: | |
| 588 return number; | |
| 589 case FLOAT_T: | |
| 590 return make_float (ratio_to_double (XRATIO_DATA (number))); | |
| 591 case BIGFLOAT_T: | |
| 592 #ifdef HAVE_BIGFLOAT | |
| 593 { | |
| 594 Lisp_Object temp; | |
| 595 temp = make_bigfloat (0.0, precision); | |
| 596 bigfloat_set_ratio (XBIGFLOAT_DATA (temp), XRATIO_DATA (number)); | |
| 597 return temp; | |
| 598 } | |
| 599 #else | |
| 2500 | 600 ABORT (); |
| 1983 | 601 #endif /* HAVE_BIGFLOAT */ |
| 602 } | |
| 603 #else | |
| 2500 | 604 ABORT (); |
| 1983 | 605 #endif /* HAVE_RATIO */ |
| 606 case FLOAT_T: | |
| 607 switch (type) | |
| 608 { | |
| 609 case FIXNUM_T: | |
|
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3391
diff
changeset
|
610 return Ftruncate (number, Qnil); |
| 1983 | 611 case BIGNUM_T: |
| 612 #ifdef HAVE_BIGNUM | |
| 613 bignum_set_double (scratch_bignum, XFLOAT_DATA (number)); | |
| 614 return make_bignum_bg (scratch_bignum); | |
| 615 #else | |
| 2500 | 616 ABORT (); |
| 1983 | 617 #endif /* HAVE_BIGNUM */ |
| 618 case RATIO_T: | |
| 619 #ifdef HAVE_RATIO | |
| 620 ratio_set_double (scratch_ratio, XFLOAT_DATA (number)); | |
| 621 return make_ratio_rt (scratch_ratio); | |
| 622 #else | |
| 2500 | 623 ABORT (); |
| 1983 | 624 #endif /* HAVE_RATIO */ |
| 625 case FLOAT_T: | |
| 626 return number; | |
| 627 case BIGFLOAT_T: | |
| 628 #ifdef HAVE_BIGFLOAT | |
| 629 bigfloat_set_prec (scratch_bigfloat, precision); | |
| 630 bigfloat_set_double (scratch_bigfloat, XFLOAT_DATA (number)); | |
| 631 return make_bigfloat_bf (scratch_bigfloat); | |
| 632 #else | |
| 2500 | 633 ABORT (); |
| 1983 | 634 #endif /* HAVE_BIGFLOAT */ |
| 635 } | |
| 636 case BIGFLOAT_T: | |
| 637 #ifdef HAVE_BIGFLOAT | |
| 638 switch (type) | |
| 639 { | |
| 640 case FIXNUM_T: | |
| 641 return make_int (bigfloat_to_long (XBIGFLOAT_DATA (number))); | |
| 642 case BIGNUM_T: | |
| 643 #ifdef HAVE_BIGNUM | |
| 644 bignum_set_bigfloat (scratch_bignum, XBIGFLOAT_DATA (number)); | |
| 645 return make_bignum_bg (scratch_bignum); | |
| 646 #else | |
| 2500 | 647 ABORT (); |
| 1983 | 648 #endif /* HAVE_BIGNUM */ |
| 649 case RATIO_T: | |
| 650 #ifdef HAVE_RATIO | |
| 651 ratio_set_bigfloat (scratch_ratio, XBIGFLOAT_DATA (number)); | |
| 652 return make_ratio_rt (scratch_ratio); | |
| 653 #else | |
| 2500 | 654 ABORT (); |
| 1983 | 655 #endif |
| 656 case FLOAT_T: | |
| 657 return make_float (bigfloat_to_double (XBIGFLOAT_DATA (number))); | |
| 658 case BIGFLOAT_T: | |
| 659 /* FIXME: Do we need to change the precision? */ | |
| 660 return number; | |
| 661 } | |
| 662 #else | |
| 2500 | 663 ABORT (); |
| 1983 | 664 #endif /* HAVE_BIGFLOAT */ |
| 665 } | |
| 2500 | 666 ABORT (); |
| 1995 | 667 /* NOTREACHED */ |
| 668 return Qzero; | |
| 1983 | 669 } |
| 670 | |
| 671 /* This function promotes its arguments as necessary to make them both the | |
| 672 same type. It destructively modifies its arguments to do so. Characters | |
| 673 and markers are ALWAYS converted to integers. */ | |
| 674 enum number_type | |
| 675 promote_args (Lisp_Object *arg1, Lisp_Object *arg2) | |
| 676 { | |
| 677 enum number_type type1, type2; | |
| 678 | |
| 679 if (CHARP (*arg1)) | |
| 680 *arg1 = make_int (XCHAR (*arg1)); | |
| 681 else if (MARKERP (*arg1)) | |
| 682 *arg1 = make_int (marker_position (*arg1)); | |
| 683 if (CHARP (*arg2)) | |
| 684 *arg2 = make_int (XCHAR (*arg2)); | |
| 685 else if (MARKERP (*arg2)) | |
| 686 *arg2 = make_int (marker_position (*arg2)); | |
| 687 | |
| 688 CHECK_NUMBER (*arg1); | |
| 689 CHECK_NUMBER (*arg2); | |
| 690 | |
| 691 type1 = get_number_type (*arg1); | |
| 692 type2 = get_number_type (*arg2); | |
| 693 | |
| 694 if (type1 < type2) | |
| 695 { | |
| 696 *arg1 = internal_coerce_number (*arg1, type2, | |
| 697 #ifdef HAVE_BIGFLOAT | |
| 698 type2 == BIGFLOAT_T | |
| 699 ? XBIGFLOAT_GET_PREC (*arg2) : | |
| 700 #endif | |
| 701 0UL); | |
| 702 return type2; | |
| 703 } | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
704 |
| 1983 | 705 if (type2 < type1) |
| 706 { | |
| 707 *arg2 = internal_coerce_number (*arg2, type1, | |
| 708 #ifdef HAVE_BIGFLOAT | |
| 709 type1 == BIGFLOAT_T | |
| 710 ? XBIGFLOAT_GET_PREC (*arg1) : | |
| 711 #endif | |
| 712 0UL); | |
| 713 return type1; | |
| 714 } | |
| 715 | |
| 716 /* No conversion necessary */ | |
| 717 return type1; | |
| 718 } | |
| 719 | |
| 720 DEFUN ("coerce-number", Fcoerce_number, 2, 3, 0, /* | |
| 721 Convert NUMBER to the indicated type, possibly losing information. | |
| 722 Do not call this function. Use `coerce' instead. | |
| 723 | |
| 3025 | 724 TYPE is one of the symbols `fixnum', `integer', `ratio', `float', or |
| 725 `bigfloat'. Not all of these types may be supported. | |
| 1983 | 726 |
| 727 PRECISION is the number of bits of precision to use when converting to | |
| 728 bigfloat; it is ignored otherwise. If nil, the default precision is used. | |
| 729 | |
| 730 Note that some conversions lose information. No error is signaled in such | |
| 731 cases; the information is silently lost. | |
| 732 */ | |
| 2595 | 733 (number, type, USED_IF_BIGFLOAT (precision))) |
| 1983 | 734 { |
| 735 CHECK_SYMBOL (type); | |
| 736 if (EQ (type, Qfixnum)) | |
| 737 return internal_coerce_number (number, FIXNUM_T, 0UL); | |
| 738 else if (EQ (type, Qinteger)) | |
| 739 { | |
| 740 /* If bignums are available, we always convert to one first, then | |
| 741 downgrade to a fixnum if possible. */ | |
| 742 #ifdef HAVE_BIGNUM | |
| 743 return Fcanonicalize_number | |
| 744 (internal_coerce_number (number, BIGNUM_T, 0UL)); | |
| 745 #else | |
| 746 return internal_coerce_number (number, FIXNUM_T, 0UL); | |
| 747 #endif | |
| 748 } | |
| 749 #ifdef HAVE_RATIO | |
| 750 else if (EQ (type, Qratio)) | |
| 751 return internal_coerce_number (number, RATIO_T, 0UL); | |
| 752 #endif | |
| 753 else if (EQ (type, Qfloat)) | |
| 754 return internal_coerce_number (number, FLOAT_T, 0UL); | |
| 755 #ifdef HAVE_BIGFLOAT | |
| 756 else if (EQ (type, Qbigfloat)) | |
| 757 { | |
| 758 unsigned long prec; | |
| 759 | |
| 760 if (NILP (precision)) | |
| 761 prec = bigfloat_get_default_prec (); | |
| 762 else | |
| 763 { | |
| 764 CHECK_INTEGER (precision); | |
| 765 #ifdef HAVE_BIGNUM | |
| 766 if (INTP (precision)) | |
| 767 #endif /* HAVE_BIGNUM */ | |
| 768 prec = (unsigned long) XREALINT (precision); | |
| 769 #ifdef HAVE_BIGNUM | |
| 770 else | |
| 771 { | |
| 772 if (!bignum_fits_ulong_p (XBIGNUM_DATA (precision))) | |
| 773 args_out_of_range (precision, Vbigfloat_max_prec); | |
| 774 prec = bignum_to_ulong (XBIGNUM_DATA (precision)); | |
| 775 } | |
| 776 #endif /* HAVE_BIGNUM */ | |
| 777 } | |
| 778 return internal_coerce_number (number, BIGFLOAT_T, prec); | |
| 779 } | |
| 780 #endif /* HAVE_BIGFLOAT */ | |
| 781 | |
| 782 Fsignal (Qunsupported_type, type); | |
| 783 /* NOTREACHED */ | |
| 784 return Qnil; | |
| 785 } | |
| 786 | |
| 787 | |
| 788 void | |
| 789 syms_of_number (void) | |
| 790 { | |
| 791 #ifdef HAVE_BIGNUM | |
| 792 INIT_LRECORD_IMPLEMENTATION (bignum); | |
| 793 #endif | |
| 794 #ifdef HAVE_RATIO | |
| 795 INIT_LRECORD_IMPLEMENTATION (ratio); | |
| 796 #endif | |
| 797 #ifdef HAVE_BIGFLOAT | |
| 798 INIT_LRECORD_IMPLEMENTATION (bigfloat); | |
| 799 #endif | |
| 800 | |
| 801 /* Type predicates */ | |
| 802 DEFSYMBOL (Qrationalp); | |
| 803 DEFSYMBOL (Qfloatingp); | |
| 804 DEFSYMBOL (Qrealp); | |
| 805 DEFSYMBOL (Qbignump); | |
| 806 DEFSYMBOL (Qratiop); | |
| 807 DEFSYMBOL (Qbigfloatp); | |
| 808 | |
| 809 /* Functions */ | |
| 810 DEFSUBR (Fbignump); | |
| 811 DEFSUBR (Fintegerp); | |
| 812 DEFSUBR (Fevenp); | |
| 813 DEFSUBR (Foddp); | |
| 814 DEFSUBR (Fratiop); | |
| 815 DEFSUBR (Frationalp); | |
| 816 DEFSUBR (Fnumerator); | |
| 817 DEFSUBR (Fdenominator); | |
| 818 DEFSUBR (Fbigfloatp); | |
| 2092 | 819 DEFSUBR (Fbigfloat_get_precision); |
| 820 DEFSUBR (Fbigfloat_set_precision); | |
| 2001 | 821 DEFSUBR (Ffloatingp); |
| 1983 | 822 DEFSUBR (Frealp); |
| 823 DEFSUBR (Fcanonicalize_number); | |
| 824 DEFSUBR (Fcoerce_number); | |
| 825 | |
| 826 /* Errors */ | |
| 827 DEFERROR_STANDARD (Qunsupported_type, Qwrong_type_argument); | |
| 828 } | |
| 829 | |
| 830 void | |
| 831 vars_of_number (void) | |
| 832 { | |
| 2051 | 833 /* These variables are Lisp variables rather than number variables so that |
| 834 we can put bignums in them. */ | |
| 1983 | 835 DEFVAR_LISP_MAGIC ("default-float-precision", &Vdefault_float_precision, /* |
| 836 The default floating-point precision for newly created floating point values. | |
| 2092 | 837 This should be 0 to create Lisp float types, or an unsigned integer no greater |
| 838 than `bigfloat-maximum-precision' to create Lisp bigfloat types with the | |
| 839 indicated precision. | |
| 1983 | 840 */ default_float_precision_changed); |
| 841 Vdefault_float_precision = make_int (0); | |
| 842 | |
| 2092 | 843 DEFVAR_CONST_LISP ("bigfloat-maximum-precision", &Vbigfloat_max_prec /* |
| 1983 | 844 The maximum number of bits of precision a bigfloat can have. |
| 2092 | 845 This is determined by the underlying library used to implement bigfloats. |
| 1983 | 846 */); |
| 847 | |
| 2061 | 848 #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
|
849 /* 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
|
850 See reinit_vars_of_number(). */ |
| 2061 | 851 Vbigfloat_max_prec = make_int (EMACS_INT_MAX); |
| 852 #else | |
| 2051 | 853 Vbigfloat_max_prec = make_int (0); |
| 854 #endif /* HAVE_BIGFLOAT */ | |
| 855 | |
| 1983 | 856 DEFVAR_CONST_INT ("most-negative-fixnum", &Vmost_negative_fixnum /* |
| 857 The fixnum closest in value to negative infinity. | |
| 858 */); | |
| 859 Vmost_negative_fixnum = EMACS_INT_MIN; | |
| 860 | |
| 861 DEFVAR_CONST_INT ("most-positive-fixnum", &Vmost_positive_fixnum /* | |
| 862 The fixnum closest in value to positive infinity. | |
| 863 */); | |
| 864 Vmost_positive_fixnum = EMACS_INT_MAX; | |
| 865 | |
| 866 Fprovide (intern ("number-types")); | |
| 867 #ifdef HAVE_BIGNUM | |
| 868 Fprovide (intern ("bignum")); | |
| 869 #endif | |
| 870 #ifdef HAVE_RATIO | |
| 871 Fprovide (intern ("ratio")); | |
| 872 #endif | |
| 873 #ifdef HAVE_BIGFLOAT | |
| 874 Fprovide (intern ("bigfloat")); | |
| 875 #endif | |
| 876 } | |
| 877 | |
| 878 void | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
879 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
|
880 { |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
881 #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
|
882 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
|
883 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
|
884 #endif |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
885 } |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
886 |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
887 void |
| 1983 | 888 init_number (void) |
| 889 { | |
| 890 if (!number_initialized) | |
| 891 { | |
| 892 number_initialized = 1; | |
| 893 | |
| 894 #ifdef WITH_GMP | |
| 895 init_number_gmp (); | |
| 896 #endif | |
| 897 #ifdef WITH_MP | |
| 898 init_number_mp (); | |
| 899 #endif | |
| 900 | |
| 901 #ifdef HAVE_BIGNUM | |
| 902 bignum_init (scratch_bignum); | |
| 903 bignum_init (scratch_bignum2); | |
| 904 #endif | |
| 905 | |
| 906 #ifdef HAVE_RATIO | |
| 907 ratio_init (scratch_ratio); | |
|
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3391
diff
changeset
|
908 ratio_init (scratch_ratio2); |
| 1983 | 909 #endif |
| 910 | |
| 911 #ifdef HAVE_BIGFLOAT | |
| 912 bigfloat_init (scratch_bigfloat); | |
| 913 bigfloat_init (scratch_bigfloat2); | |
| 914 #endif | |
|
4802
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
915 |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
916 #ifndef PDUMP |
|
2fc0e2f18322
Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
917 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
|
918 #endif |
| 1983 | 919 } |
| 920 } |
