diff options
| author | Paul Eggert | 2018-08-01 18:53:31 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-01 19:01:51 -0700 |
| commit | d216d7d248199aa6c99cd642116717c5b301ae6d (patch) | |
| tree | 687b9efadbb87fa1095fb0a2e0569e625856e15a /src/print.c | |
| parent | 2f37ecaefcc61b0bf389f1c1eb3ac1b15105f056 (diff) | |
| download | emacs-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 'src/print.c')
| -rw-r--r-- | src/print.c | 25 |
1 files changed, 3 insertions, 22 deletions
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)) |