[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/bignum b2f3f4e 04/24: Provide new functions to cre
From: |
Tom Tromey |
Subject: |
[Emacs-diffs] feature/bignum b2f3f4e 04/24: Provide new functions to create bignums |
Date: |
Fri, 13 Jul 2018 00:25:07 -0400 (EDT) |
branch: feature/bignum
commit b2f3f4ee29ba8510d3cad8025d9ce2c2014b1b7f
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>
Provide new functions to create bignums
* src/alloc.c (make_bignum_str, make_number): New functions.
* src/lisp.h (make_bignum_str, make_number): Declare.
---
src/alloc.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
src/lisp.h | 3 +++
2 files changed, 48 insertions(+)
diff --git a/src/alloc.c b/src/alloc.c
index 8ebf3e0..b775948 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3780,6 +3780,51 @@ build_marker (struct buffer *buf, ptrdiff_t charpos,
ptrdiff_t bytepos)
}
+
+Lisp_Object
+make_bignum_str (const char *num, int base)
+{
+ Lisp_Object obj;
+ struct Lisp_Bignum *b;
+ int check;
+
+ obj = allocate_misc (Lisp_Misc_Bignum);
+ b = XBIGNUM (obj);
+ mpz_init (b->value);
+ check = mpz_set_str (b->value, num, base);
+ eassert (check == 0);
+ return obj;
+}
+
+/* Given an mpz_t, make a number. This may return a bignum or a
+ fixnum depending on VALUE. */
+
+Lisp_Object
+make_number (mpz_t value)
+{
+ Lisp_Object obj;
+ struct Lisp_Bignum *b;
+
+ if (mpz_fits_slong_p (value))
+ {
+ long l = mpz_get_si (value);
+ if (!FIXNUM_OVERFLOW_P (l))
+ {
+ XSETINT (obj, l);
+ return obj;
+ }
+ }
+
+ obj = allocate_misc (Lisp_Misc_Bignum);
+ b = XBIGNUM (obj);
+ /* We could mpz_init + mpz_swap here, to avoid a copy, but the
+ resulting API seemed possibly confusing. */
+ mpz_init_set (b->value, value);
+
+ return obj;
+}
+
+
/* Return a newly created vector or string with specified arguments as
elements. If all the arguments are characters that can fit
in a string of events, make a string; otherwise, make a vector.
diff --git a/src/lisp.h b/src/lisp.h
index 37e43b0..6a3db24 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3643,6 +3643,9 @@ extern Lisp_Object list5 (Lisp_Object, Lisp_Object,
Lisp_Object, Lisp_Object,
enum constype {CONSTYPE_HEAP, CONSTYPE_PURE};
extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...);
+extern Lisp_Object make_bignum_str (const char *num, int base);
+extern Lisp_Object make_number (mpz_t value);
+
/* Build a frequently used 2/3/4-integer lists. */
INLINE Lisp_Object
- [Emacs-diffs] branch feature/bignum created (now cc3d758), Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum eefa65e 07/24: Make comparison operators handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum b2f3f4e 04/24: Provide new functions to create bignums,
Tom Tromey <=
- [Emacs-diffs] feature/bignum 580d173 05/24: Make eql work for bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum a0f2adb 03/24: Introduce the bignum type, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 23eab9a 10/24: Make number-to-string work for bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 025adce 13/24: Make abs handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 6d4bf2c 09/24: Add some bignum tests, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 872faab 12/24: Allow conversion of bignums to floats, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 5875fba 08/24: Make arithmetic work with bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum a770fb4 16/24: Make logcount handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 0d86891 14/24: Make 1+ and 1- handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 8fb995b 17/24: Make min and max handle bignums, Tom Tromey, 2018/07/13