From: Paul Eggert <eggert@cs.ucla.edu>
To: Ken Raeburn <raeburn@raeburn.org>
Cc: Tom Tromey <tom@tromey.com>,
Stefan Monnier <monnier@IRO.UMontreal.CA>,
Richard Stallman <rms@gnu.org>,
emacs-devel@gnu.org
Subject: Re: Using the GNU GMP Library for Bignums in Emacs
Date: Wed, 1 Aug 2018 00:57:09 -0700 [thread overview]
Message-ID: <94d69bf6-d186-3607-5b1d-9dee4a08ace1@cs.ucla.edu> (raw)
In-Reply-To: <5b3be3f4-d438-166a-863a-587c880584c8@cs.ucla.edu>
[-- Attachment #1: Type: text/plain, Size: 1233 bytes --]
On July 22 I wrote:
> I see three ways to go here.
>
> 1. We change eql, memql, sxhash-eql, etc. to treat all NaNs alike, so that there
> is just one NaN value from the Lisp point of view. We also change 'format',
> 'copysign' etc. to ignore a NaN's sign, and look through any other use of
> floating-point values to make sure that NaN signs are ignored.
>
> 2. We change eql, memql, sxhash-eql, etc. so that only the sign (not the
> significand) of a NaN is looked at, so that there are just two NaN values from
> the Lisp point of view.
>
> 3. We alter 'read', 'format' etc. to read and generate NaN significands. For
> example, (format "%s" NaN) could return "0.1e+NaN" if the significand's
> low-order bit was set.
>
> (1) sounds too drastic, as the sign of a NaN can be useful in some cases and
> Emacs has long provided for obtaining the sign of a NaN. Although either (2) or
> (3) would be OK, I'm inclined to go for (3) as I expect it would be a bit
> cleaner and more useful.
No further comment on this, and I went with (3) and installed into master the
attached patch to do something along those lines on platforms that have
ieee754.h (mostly GNUish platforms, I expect). Other platforms are unaffected.
[-- Attachment #2: 0001-Read-and-print-NaN-significand-if-ieee754.h.patch --]
[-- Type: text/x-patch, Size: 4330 bytes --]
From 6e37d2fd05bea373c472af1c6e80238ace5e1c94 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 1 Aug 2018 00:49:39 -0700
Subject: [PATCH] Read and print NaN significand if <ieee754.h>
* configure.ac: Check for ieee754.h.
* doc/lispref/numbers.texi (Float Basics): Document
that NaN string representation digits are machine-dependent.
* etc/NEWS: Mention the change.
* src/lread.c, src/print.c [HAVE_IEEE754_H]: Include ieee754.h.
* src/lread.c (string_to_number) [HAVE_IEEE754_H]:
* src/print.c (float_to_string) [HAVE_IEEE754_H]:
Read and print NaN significand.
---
configure.ac | 1 +
doc/lispref/numbers.texi | 2 +-
etc/NEWS | 3 +++
src/lread.c | 11 +++++++++++
src/print.c | 11 +++++++++++
5 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index b691867..dbdcce7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1668,6 +1668,7 @@ AC_DEFUN
dnl checks for header files
AC_CHECK_HEADERS_ONCE(
+ ieee754.h
linux/fs.h
malloc.h
sys/systeminfo.h
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi
index 14d5059..a3317c9 100644
--- a/doc/lispref/numbers.texi
+++ b/doc/lispref/numbers.texi
@@ -241,7 +241,7 @@ Float Basics
NaNs carry a sign and a significand, and non-numeric functions treat
two NaNs as equal when their
signs and significands agree. Significands of NaNs are
-machine-dependent and are not directly visible to Emacs Lisp.
+machine-dependent, as are the digits in their string representation.
When NaNs and signed zeros are involved, non-numeric functions like
@code{eql}, @code{equal}, @code{sxhash-eql}, @code{sxhash-equal} and
diff --git a/etc/NEWS b/etc/NEWS
index f1ea835..9e7a765 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -880,6 +880,9 @@ Formerly, some of these functions ignored signs and significands of
NaNs. Now, all these functions treat NaN signs and significands as
significant. For example, (eql 0.0e+NaN -0.0e+NaN) now returns nil
because the two NaNs have different signs; formerly it returned t.
+Also, on platforms that have <ieee754.h> Emacs now reads and prints
+NaN significands; e.g., if X is a NaN, (format "%s" X) now returns
+"0.0e+NaN", "1.0e+NaN", etc., depending on X's significand.
+++
** The function 'make-string' accepts an additional optional argument.
diff --git a/src/lread.c b/src/lread.c
index 50fc6ef..290b0f6 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -72,6 +72,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#define file_tell ftell
#endif
+#if HAVE_IEEE754_H
+# include <ieee754.h>
+#endif
+
/* The objects or placeholders read with the #n=object form.
A hash table maps a number to either a placeholder (while the
@@ -3757,8 +3761,15 @@ string_to_number (char const *string, int base, int flags)
{
state |= E_EXP;
cp += 3;
+#if HAVE_IEEE754_H
+ union ieee754_double u
+ = { .ieee_nan = { .exponent = -1, .quiet_nan = 1,
+ .mantissa0 = n >> 31 >> 1, .mantissa1 = n }};
+ value = u.d;
+#else
/* NAN is a "positive" NaN on all known Emacs hosts. */
value = NAN;
+#endif
}
else
cp = ecp;
diff --git a/src/print.c b/src/print.c
index da6ec1a..add2160 100644
--- a/src/print.c
+++ b/src/print.c
@@ -40,6 +40,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include <ftoastr.h>
#include <math.h>
+#if HAVE_IEEE754_H
+# include <ieee754.h>
+#endif
+
#ifdef WINDOWSNT
# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */
#endif
@@ -1011,6 +1015,12 @@ float_to_string (char *buf, double data)
}
if (isnan (data))
{
+#if HAVE_IEEE754_H
+ union ieee754_double u = { .d = data };
+ uprintmax_t hi = u.ieee_nan.mantissa0;
+ return sprintf (buf, &"-%"pMu".0e+NaN"[!u.ieee_nan.negative],
+ (hi << 31 << 1) + u.ieee_nan.mantissa1);
+#else
/* Prepend "-" if the NaN's sign bit is negative.
The sign bit of a double is the bit that is 1 in -0.0. */
static char const NaN_string[] = "0.0e+NaN";
@@ -1029,6 +1039,7 @@ float_to_string (char *buf, double data)
strcpy (buf + negative, NaN_string);
return negative + sizeof NaN_string - 1;
+#endif
}
if (NILP (Vfloat_output_format)
--
2.7.4
next prev parent reply other threads:[~2018-08-01 7:57 UTC|newest]
Thread overview: 281+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-21 14:15 Using the GNU GMP Library for Bignums in Emacs Siraphob (Ben) Phipathananunth
2018-04-21 14:34 ` Eli Zaretskii
2018-04-21 15:01 ` Siraphob (Ben) Phipathananunth
2018-04-21 15:23 ` Paul Eggert
2018-04-21 15:36 ` Eli Zaretskii
2018-04-21 15:40 ` Siraphob (Ben) Phipathananunth
2018-04-21 15:54 ` Eli Zaretskii
2018-04-21 16:08 ` Paul Eggert
2018-04-26 3:17 ` Tom Tromey
2018-04-26 3:33 ` Stefan Monnier
2018-04-27 15:56 ` Richard Stallman
2018-04-27 16:08 ` Stefan Monnier
2018-04-21 22:42 ` Richard Stallman
2018-04-22 2:48 ` dancol
2018-04-22 13:00 ` Philipp Stephani
2018-04-22 17:43 ` Paul Eggert
2018-04-22 18:04 ` Daniel Colascione
2018-04-22 18:34 ` Clément Pit-Claudel
2018-04-23 3:39 ` Richard Stallman
2018-04-22 8:00 ` Siraphob (Ben) Phipathananunth
2018-04-22 9:06 ` Paul Eggert
2018-04-23 5:19 ` Helmut Eller
2018-04-23 8:39 ` Andreas Schwab
2018-04-23 14:36 ` Paul Eggert
2018-04-23 19:22 ` Helmut Eller
2018-04-23 20:26 ` Paul Eggert
2018-04-23 3:36 ` Richard Stallman
2018-04-22 12:43 ` Helmut Eller
2018-04-22 17:47 ` Paul Eggert
2018-04-23 3:39 ` Richard Stallman
2018-04-23 4:41 ` Paul Eggert
2018-04-24 2:54 ` Richard Stallman
2018-04-24 2:54 ` Richard Stallman
2018-04-24 4:35 ` Paul Eggert
2018-04-24 5:45 ` Helmut Eller
2018-06-03 23:44 ` Jefferson Carpenter
2018-04-25 1:05 ` Richard Stallman
2018-04-25 1:19 ` Paul Eggert
2018-04-25 22:40 ` Richard Stallman
2018-04-25 23:29 ` Paul Eggert
2018-04-30 3:07 ` Richard Stallman
2018-04-30 5:00 ` Michael Welsh Duggan
2018-04-30 12:34 ` Stefan Monnier
2018-05-01 3:01 ` Richard Stallman
2018-04-30 7:04 ` Paul Eggert
2018-05-01 3:01 ` Richard Stallman
2018-05-01 21:45 ` Paul Eggert
2018-05-03 3:34 ` Richard Stallman
2018-05-03 5:53 ` Paul Eggert
2018-05-03 6:26 ` Helmut Eller
2018-05-03 17:49 ` Eli Zaretskii
2018-05-03 18:26 ` Paul Eggert
2018-05-04 4:26 ` Richard Stallman
2018-05-05 5:03 ` Ken Raeburn
2018-05-06 3:12 ` Richard Stallman
2018-05-07 17:24 ` Ken Raeburn
2018-05-08 1:55 ` Richard Stallman
2018-05-07 18:40 ` Andreas Schwab
2018-05-03 18:51 ` Helmut Eller
[not found] ` <83sh78o6af.fsf@gnu.org>
2018-05-03 20:30 ` Helmut Eller
2018-05-03 21:48 ` Paul Eggert
2018-05-04 4:22 ` Richard Stallman
2018-04-23 3:03 ` Stefan Monnier
2018-07-05 21:29 ` Tom Tromey
2018-07-05 21:53 ` John Wiegley
2018-07-06 20:43 ` Tom Tromey
2018-07-06 21:00 ` Paul Eggert
2018-07-07 4:27 ` Tom Tromey
2018-07-07 4:53 ` Paul Eggert
2018-07-07 6:20 ` Tom Tromey
2018-07-07 6:38 ` Paul Eggert
2018-07-09 5:37 ` Tom Tromey
2018-07-09 16:22 ` Paul Eggert
2018-07-09 22:56 ` Tom Tromey
2018-07-09 23:02 ` Paul Eggert
2018-07-09 23:13 ` Tom Tromey
2018-07-10 4:01 ` Tom Tromey
2018-07-10 13:46 ` Tom Tromey
2018-07-08 15:59 ` Tom Tromey
2018-07-09 5:43 ` Tom Tromey
2018-07-10 4:10 ` Stefan Monnier
2018-07-07 23:43 ` Richard Stallman
2018-07-08 4:58 ` Paul Eggert
2018-07-08 22:55 ` Richard Stallman
2018-07-08 5:01 ` Tom Tromey
2018-07-08 22:55 ` Richard Stallman
2018-07-09 5:39 ` Tom Tromey
2018-07-09 20:15 ` Stefan Monnier
2018-07-09 23:25 ` Paul Eggert
2018-07-10 3:41 ` Stefan Monnier
2018-07-10 5:32 ` Helmut Eller
2018-07-10 13:54 ` Stefan Monnier
2018-07-10 16:01 ` Paul Eggert
2018-07-10 16:48 ` Helmut Eller
2018-07-10 17:45 ` Paul Eggert
2018-07-10 19:14 ` Helmut Eller
2018-07-11 1:31 ` Stefan Monnier
2018-07-11 5:59 ` Helmut Eller
2018-07-11 14:23 ` Stefan Monnier
2018-07-11 2:04 ` Tom Tromey
2018-07-11 2:36 ` Paul Eggert
2018-07-10 20:33 ` Stefan Monnier
2018-07-11 1:52 ` Tom Tromey
2018-07-11 2:35 ` Paul Eggert
2018-07-11 3:16 ` Stefan Monnier
2018-07-11 3:30 ` Paul Eggert
2018-07-11 3:42 ` Stefan Monnier
2018-07-11 22:48 ` Richard Stallman
2018-07-12 4:51 ` Tom Tromey
2018-07-12 23:35 ` Richard Stallman
2018-07-15 15:02 ` Stefan Monnier
2018-07-18 10:20 ` Paul Eggert
2018-07-18 13:17 ` Stefan Monnier
2018-07-27 21:14 ` Making 'eq' == 'eql' in bignum branch Paul Eggert
2018-07-28 14:26 ` Stefan Monnier
2018-07-29 3:34 ` Paul Eggert
2018-07-29 4:09 ` Stefan Monnier
2018-07-29 14:35 ` Eli Zaretskii
2018-07-30 17:07 ` Stefan Monnier
2018-07-30 18:49 ` Eli Zaretskii
2018-07-30 20:10 ` Stefan Monnier
2018-07-30 21:58 ` Paul Eggert
2018-07-31 2:38 ` Eli Zaretskii
2018-07-31 7:10 ` Paul Eggert
2018-07-31 16:12 ` Eli Zaretskii
2018-07-31 22:44 ` Paul Eggert
2018-08-01 5:51 ` Eli Zaretskii
2018-08-01 6:43 ` Paul Eggert
2018-08-01 8:53 ` Eli Zaretskii
2018-08-03 7:40 ` Paul Eggert
2018-08-03 7:55 ` Eli Zaretskii
2018-08-10 11:12 ` Pip Cet
2018-08-10 15:15 ` Stefan Monnier
2018-08-10 15:43 ` Pip Cet
2018-08-10 15:55 ` Stefan Monnier
2018-08-10 16:52 ` John Yates
2018-08-10 19:45 ` Eli Zaretskii
2018-08-10 20:48 ` Paul Eggert
2018-08-10 7:05 ` Elias Mårtenson
2018-08-10 8:02 ` Paul Eggert
[not found] ` <<83d0v4p1si.fsf@gnu.org>
2018-07-31 15:08 ` Drew Adams
2018-07-31 16:24 ` Eli Zaretskii
2018-07-31 22:21 ` Paul Eggert
2018-08-20 0:04 ` Stefan Monnier
2018-08-20 1:33 ` Paul Eggert
2018-08-20 15:20 ` Stefan Monnier
2018-08-20 6:35 ` Pip Cet
2018-08-20 7:05 ` Paul Eggert
2018-08-20 7:19 ` Pip Cet
2018-08-20 7:27 ` Paul Eggert
2018-08-20 8:49 ` Andy Moreton
2018-08-20 16:03 ` Paul Eggert
2018-08-20 16:41 ` Andy Moreton
2018-08-20 16:51 ` Paul Eggert
2018-08-20 16:58 ` Andy Moreton
2018-08-20 19:50 ` Pip Cet
2018-08-20 21:54 ` Andy Moreton
2018-08-21 3:38 ` Richard Stallman
2018-08-20 17:23 ` Eli Zaretskii
2018-08-20 17:35 ` Paul Eggert
2018-08-20 15:13 ` Eli Zaretskii
2018-08-20 15:26 ` Stefan Monnier
2018-08-20 16:19 ` Eli Zaretskii
2018-08-21 15:01 ` Robert Pluim
2018-08-21 19:09 ` Robert Pluim
2018-08-21 19:35 ` Paul Eggert
2018-08-22 8:26 ` Lars Ingebrigtsen
2018-08-22 13:22 ` Herring, Davis
2018-08-22 13:28 ` Lars Ingebrigtsen
2018-08-22 13:55 ` Paul Eggert
2018-08-22 20:01 ` Stefan Monnier
2018-08-23 8:13 ` Robert Pluim
2018-08-23 13:45 ` Eli Zaretskii
2018-08-23 14:48 ` Robert Pluim
2018-08-23 18:43 ` Stefan Monnier
2018-08-24 9:51 ` Robert Pluim
2018-08-25 17:59 ` Stefan Monnier
2018-08-20 16:01 ` Paul Eggert
2018-08-20 16:26 ` Eli Zaretskii
2018-08-21 3:37 ` Richard Stallman
2018-08-20 15:12 ` Eli Zaretskii
2018-08-20 15:26 ` Lars Ingebrigtsen
2018-08-20 16:18 ` Eli Zaretskii
2018-08-22 19:59 ` Stefan Monnier
2018-08-21 3:38 ` Richard Stallman
2018-08-25 23:27 ` Paul Eggert
2018-08-26 12:45 ` Tramp and fixnum (was: Making 'eq' == 'eql' in bignum branch) Michael Albinus
2018-08-26 15:34 ` Paul Eggert
2018-08-26 16:06 ` Eli Zaretskii
2018-08-26 16:44 ` Tramp and fixnum Michael Albinus
2018-08-28 4:47 ` Tramp and fixnum (was: Making 'eq' == 'eql' in bignum branch) Paul Eggert
2018-08-26 16:49 ` Tramp and fixnum Michael Albinus
2018-08-28 4:48 ` Paul Eggert
2018-08-28 11:50 ` Michael Albinus
2018-08-28 14:33 ` Michael Albinus
2018-08-28 15:18 ` Paul Eggert
2018-08-29 8:09 ` Michael Albinus
2018-08-26 16:34 ` Making 'eq' == 'eql' in bignum branch Tom Tromey
2018-08-26 16:59 ` Stefan Monnier
2018-08-26 20:19 ` Alan Mackenzie
2018-08-26 20:31 ` Stefan Monnier
2018-08-27 2:31 ` Eli Zaretskii
2018-08-27 4:45 ` Stefan Monnier
2018-08-27 5:10 ` Paul Eggert
2018-08-27 14:59 ` Eli Zaretskii
2018-08-27 15:18 ` Stefan Monnier
2018-08-27 15:37 ` Eli Zaretskii
2018-08-27 15:47 ` Stefan Monnier
2018-08-27 18:57 ` Paul Eggert
2018-08-26 20:45 ` Richard Stallman
2018-08-26 22:10 ` Clément Pit-Claudel
2018-08-27 0:23 ` Paul Eggert
2018-08-27 22:50 ` Richard Stallman
2018-08-28 1:44 ` Paul Eggert
2018-08-28 14:12 ` Tom Tromey
2018-08-28 21:30 ` Richard Stallman
2018-08-28 22:03 ` Clément Pit-Claudel
2018-08-29 22:10 ` Richard Stallman
2018-08-28 18:03 ` Clément Pit-Claudel
2018-08-29 3:53 ` Stefan Monnier
2018-08-29 18:49 ` Clément Pit-Claudel
2018-08-28 1:33 ` Lars Ingebrigtsen
2018-08-28 2:25 ` Pip Cet
2018-08-28 3:45 ` Paul Eggert
2018-08-28 7:34 ` Ken Raeburn
2018-08-28 9:11 ` Helmut Eller
2018-08-28 12:15 ` Stefan Monnier
2018-08-28 18:00 ` Clément Pit-Claudel
2018-08-28 22:57 ` Pip Cet
2018-08-29 3:42 ` Herring, Davis
2018-08-29 5:40 ` Helmut Eller
2018-08-29 13:15 ` Pip Cet
2018-08-31 19:59 ` Alan Mackenzie
2018-08-31 20:30 ` Clément Pit-Claudel
2018-08-31 21:58 ` Alan Mackenzie
2018-09-01 1:26 ` Herring, Davis
2018-08-31 21:15 ` Stefan Monnier
2018-09-01 1:05 ` Herring, Davis
2018-09-02 10:57 ` Alan Mackenzie
2018-09-04 6:14 ` Herring, Davis
2018-09-01 4:47 ` Clément Pit-Claudel
2018-08-29 3:22 ` Elias Mårtenson
2018-08-29 18:56 ` Clément Pit-Claudel
2018-08-29 19:30 ` Stefan Monnier
2018-08-31 0:09 ` Stefan Monnier
2018-09-01 2:32 ` Richard Stallman
2018-08-31 16:41 ` Paul Eggert
2018-08-28 21:25 ` Richard Stallman
2018-08-30 19:13 ` Johan Bockgård
2018-08-30 21:14 ` Clément Pit-Claudel
2018-08-30 21:35 ` Tom Tromey
2018-08-30 21:56 ` Clément Pit-Claudel
2018-08-20 15:37 ` Stefan Monnier
2018-08-20 16:23 ` Eli Zaretskii
2018-08-20 16:12 ` Paul Eggert
2018-08-20 17:21 ` Helmut Eller
2018-08-20 14:02 ` Stefan Monnier
2018-07-18 15:55 ` Using the GNU GMP Library for Bignums in Emacs Eli Zaretskii
2018-07-18 21:42 ` Paul Eggert
2018-07-22 12:06 ` Ken Raeburn
2018-07-22 16:44 ` Paul Eggert
2018-08-01 7:57 ` Paul Eggert [this message]
2018-08-01 11:59 ` Eli Zaretskii
2018-08-02 2:06 ` Paul Eggert
2018-08-02 13:49 ` Eli Zaretskii
2018-07-22 19:57 ` Achim Gratz
2018-04-21 16:46 ` Markus Triska
2018-04-21 17:09 ` Eli Zaretskii
2018-04-21 17:27 ` Markus Triska
2018-04-21 18:37 ` Paul Eggert
2018-04-21 22:42 ` Richard Stallman
2018-04-22 2:43 ` Eli Zaretskii
2018-04-23 3:34 ` Richard Stallman
2018-04-23 4:21 ` Paul Eggert
2018-04-23 13:13 ` Stefan Monnier
2018-04-24 2:54 ` Richard Stallman
2018-04-24 4:34 ` Paul Eggert
2018-04-25 1:05 ` Richard Stallman
2018-04-23 15:18 ` Eli Zaretskii
2018-04-24 18:56 ` Emanuele Santoro
2018-04-26 15:52 ` Glenn Morris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=94d69bf6-d186-3607-5b1d-9dee4a08ace1@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=monnier@IRO.UMontreal.CA \
--cc=raeburn@raeburn.org \
--cc=rms@gnu.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).