aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2018-08-01 18:53:31 -0700
committerPaul Eggert2018-08-01 19:01:51 -0700
commitd216d7d248199aa6c99cd642116717c5b301ae6d (patch)
tree687b9efadbb87fa1095fb0a2e0569e625856e15a /lib
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/gnulib.mk.in29
-rw-r--r--lib/ieee754.in.h222
2 files changed, 251 insertions, 0 deletions
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 */