[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/bignum 872faab 12/24: Allow conversion of bignums
From: |
Tom Tromey |
Subject: |
[Emacs-diffs] feature/bignum 872faab 12/24: Allow conversion of bignums to floats |
Date: |
Fri, 13 Jul 2018 00:25:08 -0400 (EDT) |
branch: feature/bignum
commit 872faabbd8cb0f5518777b2d4fe7de187f684a92
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>
Allow conversion of bignums to floats
* src/floatfns.c (extract_float, Ffloat): Handle bignums.
* src/lisp.h (XFLOATINT): Handle bignums.
* test/src/floatfns-tests.el (bignum-to-float): New test.
---
src/floatfns.c | 6 ++++--
src/lisp.h | 2 ++
test/src/floatfns-tests.el | 4 ++++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/floatfns.c b/src/floatfns.c
index 766044b..bd3f2de 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -67,7 +67,7 @@ CHECK_FLOAT (Lisp_Object x)
double
extract_float (Lisp_Object num)
{
- CHECK_FIXNUM_OR_FLOAT (num);
+ CHECK_NUMBER (num);
return XFLOATINT (num);
}
@@ -289,8 +289,10 @@ DEFUN ("float", Ffloat, Sfloat, 1, 1, 0,
doc: /* Return the floating point number equal to ARG. */)
(register Lisp_Object arg)
{
- CHECK_FIXNUM_OR_FLOAT (arg);
+ CHECK_NUMBER (arg);
+ if (BIGNUMP (arg))
+ return make_float (mpz_get_d (XBIGNUM (arg)->value));
if (FIXNUMP (arg))
return make_float ((double) XINT (arg));
else /* give 'em the same float back */
diff --git a/src/lisp.h b/src/lisp.h
index be67932..63b0570 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2919,6 +2919,8 @@ CHECK_FIXNAT (Lisp_Object x)
INLINE double
XFLOATINT (Lisp_Object n)
{
+ if (BIGNUMP (n))
+ return mpz_get_d (XBIGNUM (n)->value);
return FLOATP (n) ? XFLOAT_DATA (n) : XINT (n);
}
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
index cb173ee..c87445b 100644
--- a/test/src/floatfns-tests.el
+++ b/test/src/floatfns-tests.el
@@ -34,4 +34,8 @@
(should-error (ftruncate 0) :type 'wrong-type-argument)
(should-error (fround 0) :type 'wrong-type-argument))
+(ert-deftest bignum-to-float ()
+ (should (eql (float (+ most-positive-fixnum 1))
+ (+ (float most-positive-fixnum) 1))))
+
(provide 'floatfns-tests)
- [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, 2018/07/13
- [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 <=
- [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
- [Emacs-diffs] feature/bignum 3dea8f8 19/24: Make % and mod handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum d14808c 11/24: Make format handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum c7e393b 15/24: Make lognot handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 1e8ae6c 06/24: Make the reader accept bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 27980e3 21/24: Make ash and lsh handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum cca0e79 20/24: Make logb handle bignums, Tom Tromey, 2018/07/13