diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-08-01 18:53:31 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-08-01 19:01:51 -0700 |
commit | d216d7d248199aa6c99cd642116717c5b301ae6d (patch) | |
tree | 687b9efadbb87fa1095fb0a2e0569e625856e15a /src | |
parent | 2f37ecaefcc61b0bf389f1c1eb3ac1b15105f056 (diff) | |
download | emacs-d216d7d248199aa6c99cd642116717c5b301ae6d.tar.gz |
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 'src')
-rw-r--r-- | src/lisp.h | 11 | ||||
-rw-r--r-- | src/lread.c | 9 | ||||
-rw-r--r-- | src/print.c | 25 |
3 files changed, 10 insertions, 35 deletions
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) /* Most hosts nowadays use IEEE floating point, so they use IEC 60559 representations, have infinities and NaNs, and do not trap on - exceptions. Define IEEE_FLOATING_POINT if this host is one of the + exceptions. Define IEEE_FLOATING_POINT to 1 if this host is one of the typical ones. The C11 macro __STDC_IEC_559__ is close to what is wanted here, but is not quite right because Emacs does not require all the features of C11 Annex F (and does not require C11 at all, for that matter). */ -enum - { - IEEE_FLOATING_POINT - = (FLT_RADIX == 2 && FLT_MANT_DIG == 24 - && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128) - }; + +#define IEEE_FLOATING_POINT (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ + && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128) /* A character, declared with the following typedef, is a member 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/>. */ #define file_tell ftell #endif -#if HAVE_IEEE754_H +#if IEEE_FLOATING_POINT # include <ieee754.h> #endif @@ -3756,21 +3756,18 @@ string_to_number (char const *string, int base, int flags) cp += 3; value = INFINITY; } +#if IEEE_FLOATING_POINT else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') { 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 } +#endif else cp = ecp; } 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/>. */ #include <ftoastr.h> #include <math.h> -#if HAVE_IEEE754_H +#if IEEE_FLOATING_POINT # include <ieee754.h> #endif @@ -1013,34 +1013,15 @@ float_to_string (char *buf, double data) strcpy (buf, minus_infinity_string + positive); return sizeof minus_infinity_string - 1 - positive; } +#if IEEE_FLOATING_POINT 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"; - int i; - union { double d; char c[sizeof (double)]; } u_data, u_minus_zero; - bool negative = 0; - u_data.d = data; - u_minus_zero.d = - 0.0; - for (i = 0; i < sizeof (double); i++) - if (u_data.c[i] & u_minus_zero.c[i]) - { - *buf = '-'; - negative = 1; - break; - } - - strcpy (buf + negative, NaN_string); - return negative + sizeof NaN_string - 1; -#endif } +#endif if (NILP (Vfloat_output_format) || !STRINGP (Vfloat_output_format)) |