aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2018-08-01 18:53:31 -0700
committerPaul Eggert2018-08-01 19:01:51 -0700
commitd216d7d248199aa6c99cd642116717c5b301ae6d (patch)
tree687b9efadbb87fa1095fb0a2e0569e625856e15a
parent2f37ecaefcc61b0bf389f1c1eb3ac1b15105f056 (diff)
downloademacs-d216d7d248199aa6c99cd642116717c5b301ae6d.tar.gz
emacs-d216d7d248199aa6c99cd642116717c5b301ae6d.zip
Substitute a <ieee754.h> on hosts lacking it
* .gitignore: Add lib/ieee754.h. * admin/merge-gnulib (GNULIB_MODULES): Add ieee754-h. * configure.ac: Remove ieee754.h check, as Gnulib now does that. * etc/NEWS: Mention this. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib/ieee754.in.h, m4/ieee754-h.m4: New files, from Gnulib. * src/lisp.h (IEEE_FLOATING_POINT): Now a macro so that it can be used in #if. * src/lread.c, src/print.c: Include <ieee754.h> if IEEE_FLOATING_POINT, not if HAVE_IEEE754_H. * src/lread.c (string_to_number): * src/print.c (float_to_string): Process NaNs only on IEEE hosts, and assume <ieee754.h> in that case.
-rw-r--r--.gitignore1
-rwxr-xr-xadmin/merge-gnulib2
-rw-r--r--configure.ac1
-rw-r--r--etc/NEWS6
-rw-r--r--lib/gnulib.mk.in29
-rw-r--r--lib/ieee754.in.h222
-rw-r--r--m4/gnulib-comp.m44
-rw-r--r--m4/ieee754-h.m421
-rw-r--r--src/lisp.h11
-rw-r--r--src/lread.c9
-rw-r--r--src/print.c25
11 files changed, 291 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index d3712b0d6cf..26fe4bb34e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,6 +57,7 @@ lib/execinfo.h
57lib/fcntl.h 57lib/fcntl.h
58lib/getopt.h 58lib/getopt.h
59lib/getopt-cdefs.h 59lib/getopt-cdefs.h
60lib/ieee754.h
60lib/inttypes.h 61lib/inttypes.h
61lib/libgnu.a 62lib/libgnu.a
62lib/limits.h 63lib/limits.h
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index 39dfaee8f4d..1397ecfb9f7 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -35,7 +35,7 @@ GNULIB_MODULES='
35 fcntl fcntl-h fdatasync fdopendir 35 fcntl fcntl-h fdatasync fdopendir
36 filemode filevercmp flexmember fpieee fstatat fsusage fsync 36 filemode filevercmp flexmember fpieee fstatat fsusage fsync
37 getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog 37 getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog
38 ignore-value intprops largefile lstat 38 ieee754-h ignore-value intprops largefile lstat
39 manywarnings memrchr minmax mkostemp mktime nstrftime 39 manywarnings memrchr minmax mkostemp mktime nstrftime
40 pipe2 pselect pthread_sigmask putenv qcopy-acl readlink readlinkat 40 pipe2 pselect pthread_sigmask putenv qcopy-acl readlink readlinkat
41 sig2str socklen stat-time std-gnu11 stdalign stddef stdio 41 sig2str socklen stat-time std-gnu11 stdalign stddef stdio
diff --git a/configure.ac b/configure.ac
index dbdcce7c8d8..b6918671e40 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1668,7 +1668,6 @@ fi
1668 1668
1669dnl checks for header files 1669dnl checks for header files
1670AC_CHECK_HEADERS_ONCE( 1670AC_CHECK_HEADERS_ONCE(
1671 ieee754.h
1672 linux/fs.h 1671 linux/fs.h
1673 malloc.h 1672 malloc.h
1674 sys/systeminfo.h 1673 sys/systeminfo.h
diff --git a/etc/NEWS b/etc/NEWS
index 9e7a765dc61..6c79a46f243 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -880,9 +880,9 @@ Formerly, some of these functions ignored signs and significands of
880NaNs. Now, all these functions treat NaN signs and significands as 880NaNs. Now, all these functions treat NaN signs and significands as
881significant. For example, (eql 0.0e+NaN -0.0e+NaN) now returns nil 881significant. For example, (eql 0.0e+NaN -0.0e+NaN) now returns nil
882because the two NaNs have different signs; formerly it returned t. 882because the two NaNs have different signs; formerly it returned t.
883Also, on platforms that have <ieee754.h> Emacs now reads and prints 883Also, Emacs now reads and prints NaN significands; e.g., if X is a
884NaN significands; e.g., if X is a NaN, (format "%s" X) now returns 884NaN, (format "%s" X) now returns "0.0e+NaN", "1.0e+NaN", etc.,
885"0.0e+NaN", "1.0e+NaN", etc., depending on X's significand. 885depending on X's significand.
886 886
887+++ 887+++
888** The function 'make-string' accepts an additional optional argument. 888** The function 'make-string' accepts an additional optional argument.
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index e623921091f..7d28dcc62b8 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -95,6 +95,7 @@
95# gettime \ 95# gettime \
96# gettimeofday \ 96# gettimeofday \
97# gitlog-to-changelog \ 97# gitlog-to-changelog \
98# ieee754-h \
98# ignore-value \ 99# ignore-value \
99# intprops \ 100# intprops \
100# largefile \ 101# largefile \
@@ -220,6 +221,7 @@ GL_GENERATE_ALLOCA_H = @GL_GENERATE_ALLOCA_H@
220GL_GENERATE_BYTESWAP_H = @GL_GENERATE_BYTESWAP_H@ 221GL_GENERATE_BYTESWAP_H = @GL_GENERATE_BYTESWAP_H@
221GL_GENERATE_ERRNO_H = @GL_GENERATE_ERRNO_H@ 222GL_GENERATE_ERRNO_H = @GL_GENERATE_ERRNO_H@
222GL_GENERATE_EXECINFO_H = @GL_GENERATE_EXECINFO_H@ 223GL_GENERATE_EXECINFO_H = @GL_GENERATE_EXECINFO_H@
224GL_GENERATE_IEEE754_H = @GL_GENERATE_IEEE754_H@
223GL_GENERATE_LIMITS_H = @GL_GENERATE_LIMITS_H@ 225GL_GENERATE_LIMITS_H = @GL_GENERATE_LIMITS_H@
224GL_GENERATE_STDALIGN_H = @GL_GENERATE_STDALIGN_H@ 226GL_GENERATE_STDALIGN_H = @GL_GENERATE_STDALIGN_H@
225GL_GENERATE_STDDEF_H = @GL_GENERATE_STDDEF_H@ 227GL_GENERATE_STDDEF_H = @GL_GENERATE_STDDEF_H@
@@ -646,6 +648,7 @@ HAVE_WINSOCK2_H = @HAVE_WINSOCK2_H@
646HAVE_XSERVER = @HAVE_XSERVER@ 648HAVE_XSERVER = @HAVE_XSERVER@
647HAVE__EXIT = @HAVE__EXIT@ 649HAVE__EXIT = @HAVE__EXIT@
648HYBRID_MALLOC = @HYBRID_MALLOC@ 650HYBRID_MALLOC = @HYBRID_MALLOC@
651IEEE754_H = @IEEE754_H@
649IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@ 652IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@
650IMAGEMAGICK_LIBS = @IMAGEMAGICK_LIBS@ 653IMAGEMAGICK_LIBS = @IMAGEMAGICK_LIBS@
651INCLUDE_NEXT = @INCLUDE_NEXT@ 654INCLUDE_NEXT = @INCLUDE_NEXT@
@@ -1787,6 +1790,32 @@ EXTRA_libgnu_a_SOURCES += group-member.c
1787endif 1790endif
1788## end gnulib module group-member 1791## end gnulib module group-member
1789 1792
1793## begin gnulib module ieee754-h
1794ifeq (,$(OMIT_GNULIB_MODULE_ieee754-h))
1795
1796BUILT_SOURCES += $(IEEE754_H)
1797
1798# We need the following in order to create <ieee754.h> when the system
1799# doesn't have one that works with the given compiler.
1800ifneq (,$(GL_GENERATE_IEEE754_H))
1801ieee754.h: ieee754.in.h $(top_builddir)/config.status
1802 $(AM_V_GEN)rm -f $@-t && \
1803 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
1804 sed -e 's/ifndef _GL_GNULIB_HEADER/if 0/g' \
1805 $(srcdir)/ieee754.in.h; \
1806 } > $@-t && \
1807 mv -f $@-t $@
1808else
1809ieee754.h: $(top_builddir)/config.status
1810 rm -f $@
1811endif
1812MOSTLYCLEANFILES += ieee754.h ieee754.h-t
1813
1814EXTRA_DIST += ieee754.in.h
1815
1816endif
1817## end gnulib module ieee754-h
1818
1790## begin gnulib module ignore-value 1819## begin gnulib module ignore-value
1791ifeq (,$(OMIT_GNULIB_MODULE_ignore-value)) 1820ifeq (,$(OMIT_GNULIB_MODULE_ignore-value))
1792 1821
diff --git a/lib/ieee754.in.h b/lib/ieee754.in.h
new file mode 100644
index 00000000000..316ac039afe
--- /dev/null
+++ b/lib/ieee754.in.h
@@ -0,0 +1,222 @@
1/* Copyright (C) 1992-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _IEEE754_H
19
20#define _IEEE754_H 1
21
22#ifndef _GL_GNULIB_HEADER
23/* Ordinary glibc usage. */
24# include <features.h>
25# include <endian.h>
26#else
27/* Gnulib usage. */
28# ifndef __BEGIN_DECLS
29# ifdef __cplusplus
30# define __BEGIN_DECLS extern "C" {
31# define __END_DECLS }
32# else
33# define __BEGIN_DECLS
34# define __END_DECLS
35# endif
36# endif
37# ifndef __FLOAT_WORD_ORDER
38# define __LITTLE_ENDIAN 1234
39# define __BIG_ENDIAN 4321
40# ifdef WORDS_BIGENDIAN
41# define __BYTE_ORDER __BIG_ENDIAN
42# else
43# define __BYTE_ORDER __LITTLE_ENDIAN
44# endif
45# define __FLOAT_WORD_ORDER __BYTE_ORDER
46# endif
47#endif
48
49__BEGIN_DECLS
50
51union ieee754_float
52 {
53 float f;
54
55 /* This is the IEEE 754 single-precision format. */
56 struct
57 {
58#if __BYTE_ORDER == __BIG_ENDIAN
59 unsigned int negative:1;
60 unsigned int exponent:8;
61 unsigned int mantissa:23;
62#endif /* Big endian. */
63#if __BYTE_ORDER == __LITTLE_ENDIAN
64 unsigned int mantissa:23;
65 unsigned int exponent:8;
66 unsigned int negative:1;
67#endif /* Little endian. */
68 } ieee;
69
70 /* This format makes it easier to see if a NaN is a signalling NaN. */
71 struct
72 {
73#if __BYTE_ORDER == __BIG_ENDIAN
74 unsigned int negative:1;
75 unsigned int exponent:8;
76 unsigned int quiet_nan:1;
77 unsigned int mantissa:22;
78#endif /* Big endian. */
79#if __BYTE_ORDER == __LITTLE_ENDIAN
80 unsigned int mantissa:22;
81 unsigned int quiet_nan:1;
82 unsigned int exponent:8;
83 unsigned int negative:1;
84#endif /* Little endian. */
85 } ieee_nan;
86 };
87
88#define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
89
90
91union ieee754_double
92 {
93 double d;
94
95 /* This is the IEEE 754 double-precision format. */
96 struct
97 {
98#if __BYTE_ORDER == __BIG_ENDIAN
99 unsigned int negative:1;
100 unsigned int exponent:11;
101 /* Together these comprise the mantissa. */
102 unsigned int mantissa0:20;
103 unsigned int mantissa1:32;
104#endif /* Big endian. */
105#if __BYTE_ORDER == __LITTLE_ENDIAN
106# if __FLOAT_WORD_ORDER == __BIG_ENDIAN
107 unsigned int mantissa0:20;
108 unsigned int exponent:11;
109 unsigned int negative:1;
110 unsigned int mantissa1:32;
111# else
112 /* Together these comprise the mantissa. */
113 unsigned int mantissa1:32;
114 unsigned int mantissa0:20;
115 unsigned int exponent:11;
116 unsigned int negative:1;
117# endif
118#endif /* Little endian. */
119 } ieee;
120
121 /* This format makes it easier to see if a NaN is a signalling NaN. */
122 struct
123 {
124#if __BYTE_ORDER == __BIG_ENDIAN
125 unsigned int negative:1;
126 unsigned int exponent:11;
127 unsigned int quiet_nan:1;
128 /* Together these comprise the mantissa. */
129 unsigned int mantissa0:19;
130 unsigned int mantissa1:32;
131#else
132# if __FLOAT_WORD_ORDER == __BIG_ENDIAN
133 unsigned int mantissa0:19;
134 unsigned int quiet_nan:1;
135 unsigned int exponent:11;
136 unsigned int negative:1;
137 unsigned int mantissa1:32;
138# else
139 /* Together these comprise the mantissa. */
140 unsigned int mantissa1:32;
141 unsigned int mantissa0:19;
142 unsigned int quiet_nan:1;
143 unsigned int exponent:11;
144 unsigned int negative:1;
145# endif
146#endif
147 } ieee_nan;
148 };
149
150#define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
151
152
153union ieee854_long_double
154 {
155 long double d;
156
157 /* This is the IEEE 854 double-extended-precision format. */
158 struct
159 {
160#if __BYTE_ORDER == __BIG_ENDIAN
161 unsigned int negative:1;
162 unsigned int exponent:15;
163 unsigned int empty:16;
164 unsigned int mantissa0:32;
165 unsigned int mantissa1:32;
166#endif
167#if __BYTE_ORDER == __LITTLE_ENDIAN
168# if __FLOAT_WORD_ORDER == __BIG_ENDIAN
169 unsigned int exponent:15;
170 unsigned int negative:1;
171 unsigned int empty:16;
172 unsigned int mantissa0:32;
173 unsigned int mantissa1:32;
174# else
175 unsigned int mantissa1:32;
176 unsigned int mantissa0:32;
177 unsigned int exponent:15;
178 unsigned int negative:1;
179 unsigned int empty:16;
180# endif
181#endif
182 } ieee;
183
184 /* This is for NaNs in the IEEE 854 double-extended-precision format. */
185 struct
186 {
187#if __BYTE_ORDER == __BIG_ENDIAN
188 unsigned int negative:1;
189 unsigned int exponent:15;
190 unsigned int empty:16;
191 unsigned int one:1;
192 unsigned int quiet_nan:1;
193 unsigned int mantissa0:30;
194 unsigned int mantissa1:32;
195#endif
196#if __BYTE_ORDER == __LITTLE_ENDIAN
197# if __FLOAT_WORD_ORDER == __BIG_ENDIAN
198 unsigned int exponent:15;
199 unsigned int negative:1;
200 unsigned int empty:16;
201 unsigned int mantissa0:30;
202 unsigned int quiet_nan:1;
203 unsigned int one:1;
204 unsigned int mantissa1:32;
205# else
206 unsigned int mantissa1:32;
207 unsigned int mantissa0:30;
208 unsigned int quiet_nan:1;
209 unsigned int one:1;
210 unsigned int exponent:15;
211 unsigned int negative:1;
212 unsigned int empty:16;
213# endif
214#endif
215 } ieee_nan;
216 };
217
218#define IEEE854_LONG_DOUBLE_BIAS 0x3fff
219
220__END_DECLS
221
222#endif /* ieee754.h */
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index a6e3be3815d..494c77c7c4e 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -101,6 +101,7 @@ AC_DEFUN([gl_EARLY],
101 # Code from module gettimeofday: 101 # Code from module gettimeofday:
102 # Code from module gitlog-to-changelog: 102 # Code from module gitlog-to-changelog:
103 # Code from module group-member: 103 # Code from module group-member:
104 # Code from module ieee754-h:
104 # Code from module ignore-value: 105 # Code from module ignore-value:
105 # Code from module include_next: 106 # Code from module include_next:
106 # Code from module intprops: 107 # Code from module intprops:
@@ -295,6 +296,7 @@ AC_DEFUN([gl_INIT],
295 gl_PREREQ_GETTIMEOFDAY 296 gl_PREREQ_GETTIMEOFDAY
296 fi 297 fi
297 gl_SYS_TIME_MODULE_INDICATOR([gettimeofday]) 298 gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
299 gl_IEEE754_H
298 gl_INTTYPES_INCOMPLETE 300 gl_INTTYPES_INCOMPLETE
299 AC_REQUIRE([gl_LARGEFILE]) 301 AC_REQUIRE([gl_LARGEFILE])
300 gl_LIMITS_H 302 gl_LIMITS_H
@@ -895,6 +897,7 @@ AC_DEFUN([gl_FILE_LIST], [
895 lib/gettimeofday.c 897 lib/gettimeofday.c
896 lib/gl_openssl.h 898 lib/gl_openssl.h
897 lib/group-member.c 899 lib/group-member.c
900 lib/ieee754.in.h
898 lib/ignore-value.h 901 lib/ignore-value.h
899 lib/intprops.h 902 lib/intprops.h
900 lib/inttypes.in.h 903 lib/inttypes.in.h
@@ -1017,6 +1020,7 @@ AC_DEFUN([gl_FILE_LIST], [
1017 m4/gl-openssl.m4 1020 m4/gl-openssl.m4
1018 m4/gnulib-common.m4 1021 m4/gnulib-common.m4
1019 m4/group-member.m4 1022 m4/group-member.m4
1023 m4/ieee754-h.m4
1020 m4/include_next.m4 1024 m4/include_next.m4
1021 m4/inttypes.m4 1025 m4/inttypes.m4
1022 m4/largefile.m4 1026 m4/largefile.m4
diff --git a/m4/ieee754-h.m4 b/m4/ieee754-h.m4
new file mode 100644
index 00000000000..bf7c332e48e
--- /dev/null
+++ b/m4/ieee754-h.m4
@@ -0,0 +1,21 @@
1# Configure ieee754-h module
2
3dnl Copyright 2018 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_IEEE754_H],
9[
10 AC_REQUIRE([AC_C_BIGENDIAN])
11 AC_CHECK_HEADERS_ONCE([ieee754.h])
12 if test $ac_cv_header_ieee754_h = yes; then
13 IEEE754_H=
14 else
15 IEEE754_H=ieee754.h
16 AC_DEFINE([_GL_REPLACE_IEEE754_H], 1,
17 [Define to 1 if <ieee754.h> is missing.])
18 fi
19 AC_SUBST([IEEE754_H])
20 AM_CONDITIONAL([GL_GENERATE_IEEE754_H], [test -n "$IEEE754_H"])
21])
diff --git a/src/lisp.h b/src/lisp.h
index 96de60e4670..bdece817bd6 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2670,17 +2670,14 @@ XFLOAT_DATA (Lisp_Object f)
2670 2670
2671/* Most hosts nowadays use IEEE floating point, so they use IEC 60559 2671/* Most hosts nowadays use IEEE floating point, so they use IEC 60559
2672 representations, have infinities and NaNs, and do not trap on 2672 representations, have infinities and NaNs, and do not trap on
2673 exceptions. Define IEEE_FLOATING_POINT if this host is one of the 2673 exceptions. Define IEEE_FLOATING_POINT to 1 if this host is one of the
2674 typical ones. The C11 macro __STDC_IEC_559__ is close to what is 2674 typical ones. The C11 macro __STDC_IEC_559__ is close to what is
2675 wanted here, but is not quite right because Emacs does not require 2675 wanted here, but is not quite right because Emacs does not require
2676 all the features of C11 Annex F (and does not require C11 at all, 2676 all the features of C11 Annex F (and does not require C11 at all,
2677 for that matter). */ 2677 for that matter). */
2678enum 2678
2679 { 2679#define IEEE_FLOATING_POINT (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
2680 IEEE_FLOATING_POINT 2680 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
2681 = (FLT_RADIX == 2 && FLT_MANT_DIG == 24
2682 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
2683 };
2684 2681
2685/* A character, declared with the following typedef, is a member 2682/* A character, declared with the following typedef, is a member
2686 of some character set associated with the current buffer. */ 2683 of some character set associated with the current buffer. */
diff --git a/src/lread.c b/src/lread.c
index 290b0f6bbe9..9a025d8664d 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -72,7 +72,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
72#define file_tell ftell 72#define file_tell ftell
73#endif 73#endif
74 74
75#if HAVE_IEEE754_H 75#if IEEE_FLOATING_POINT
76# include <ieee754.h> 76# include <ieee754.h>
77#endif 77#endif
78 78
@@ -3756,21 +3756,18 @@ string_to_number (char const *string, int base, int flags)
3756 cp += 3; 3756 cp += 3;
3757 value = INFINITY; 3757 value = INFINITY;
3758 } 3758 }
3759#if IEEE_FLOATING_POINT
3759 else if (cp[-1] == '+' 3760 else if (cp[-1] == '+'
3760 && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') 3761 && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
3761 { 3762 {
3762 state |= E_EXP; 3763 state |= E_EXP;
3763 cp += 3; 3764 cp += 3;
3764#if HAVE_IEEE754_H
3765 union ieee754_double u 3765 union ieee754_double u
3766 = { .ieee_nan = { .exponent = -1, .quiet_nan = 1, 3766 = { .ieee_nan = { .exponent = -1, .quiet_nan = 1,
3767 .mantissa0 = n >> 31 >> 1, .mantissa1 = n }}; 3767 .mantissa0 = n >> 31 >> 1, .mantissa1 = n }};
3768 value = u.d; 3768 value = u.d;
3769#else
3770 /* NAN is a "positive" NaN on all known Emacs hosts. */
3771 value = NAN;
3772#endif
3773 } 3769 }
3770#endif
3774 else 3771 else
3775 cp = ecp; 3772 cp = ecp;
3776 } 3773 }
diff --git a/src/print.c b/src/print.c
index add21609cc5..34c7fa12b6e 100644
--- a/src/print.c
+++ b/src/print.c
@@ -40,7 +40,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
40#include <ftoastr.h> 40#include <ftoastr.h>
41#include <math.h> 41#include <math.h>
42 42
43#if HAVE_IEEE754_H 43#if IEEE_FLOATING_POINT
44# include <ieee754.h> 44# include <ieee754.h>
45#endif 45#endif
46 46
@@ -1013,34 +1013,15 @@ float_to_string (char *buf, double data)
1013 strcpy (buf, minus_infinity_string + positive); 1013 strcpy (buf, minus_infinity_string + positive);
1014 return sizeof minus_infinity_string - 1 - positive; 1014 return sizeof minus_infinity_string - 1 - positive;
1015 } 1015 }
1016#if IEEE_FLOATING_POINT
1016 if (isnan (data)) 1017 if (isnan (data))
1017 { 1018 {
1018#if HAVE_IEEE754_H
1019 union ieee754_double u = { .d = data }; 1019 union ieee754_double u = { .d = data };
1020 uprintmax_t hi = u.ieee_nan.mantissa0; 1020 uprintmax_t hi = u.ieee_nan.mantissa0;
1021 return sprintf (buf, &"-%"pMu".0e+NaN"[!u.ieee_nan.negative], 1021 return sprintf (buf, &"-%"pMu".0e+NaN"[!u.ieee_nan.negative],
1022 (hi << 31 << 1) + u.ieee_nan.mantissa1); 1022 (hi << 31 << 1) + u.ieee_nan.mantissa1);
1023#else
1024 /* Prepend "-" if the NaN's sign bit is negative.
1025 The sign bit of a double is the bit that is 1 in -0.0. */
1026 static char const NaN_string[] = "0.0e+NaN";
1027 int i;
1028 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
1029 bool negative = 0;
1030 u_data.d = data;
1031 u_minus_zero.d = - 0.0;
1032 for (i = 0; i < sizeof (double); i++)
1033 if (u_data.c[i] & u_minus_zero.c[i])
1034 {
1035 *buf = '-';
1036 negative = 1;
1037 break;
1038 }
1039
1040 strcpy (buf + negative, NaN_string);
1041 return negative + sizeof NaN_string - 1;
1042#endif
1043 } 1023 }
1024#endif
1044 1025
1045 if (NILP (Vfloat_output_format) 1026 if (NILP (Vfloat_output_format)
1046 || !STRINGP (Vfloat_output_format)) 1027 || !STRINGP (Vfloat_output_format))