aboutsummaryrefslogtreecommitdiffstats
path: root/src/print.c
diff options
context:
space:
mode:
authorTom Tromey2018-08-09 17:56:53 -0600
committerTom Tromey2018-08-09 17:56:53 -0600
commitaccb7b7ecc19f85c2750ded1046a464bc73c6a52 (patch)
tree1aa94af022d6700a93a8ff2b73f5b210046ac010 /src/print.c
parentf822a2516d88eeb2118fbbc8554f155e86dfd74e (diff)
parent53483df0de0085dbc9ef0b15a0f629ab808b0147 (diff)
downloademacs-accb7b7ecc19f85c2750ded1046a464bc73c6a52.tar.gz
emacs-accb7b7ecc19f85c2750ded1046a464bc73c6a52.zip
Merge remote-tracking branch 'origin/master' into feature/bignum
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c48
1 files changed, 16 insertions, 32 deletions
diff --git a/src/print.c b/src/print.c
index 998ff2dc0c6..3819c505b12 100644
--- a/src/print.c
+++ b/src/print.c
@@ -38,6 +38,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
38#include <c-ctype.h> 38#include <c-ctype.h>
39#include <float.h> 39#include <float.h>
40#include <ftoastr.h> 40#include <ftoastr.h>
41#include <math.h>
42
43#if IEEE_FLOATING_POINT
44# include <ieee754.h>
45#endif
41 46
42#ifdef WINDOWSNT 47#ifdef WINDOWSNT
43# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */ 48# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */
@@ -1001,43 +1006,22 @@ float_to_string (char *buf, double data)
1001 int width; 1006 int width;
1002 int len; 1007 int len;
1003 1008
1004 /* Check for plus infinity in a way that won't lose 1009 if (isinf (data))
1005 if there is no plus infinity. */
1006 if (data == data / 2 && data > 1.0)
1007 {
1008 static char const infinity_string[] = "1.0e+INF";
1009 strcpy (buf, infinity_string);
1010 return sizeof infinity_string - 1;
1011 }
1012 /* Likewise for minus infinity. */
1013 if (data == data / 2 && data < -1.0)
1014 { 1010 {
1015 static char const minus_infinity_string[] = "-1.0e+INF"; 1011 static char const minus_infinity_string[] = "-1.0e+INF";
1016 strcpy (buf, minus_infinity_string); 1012 bool positive = 0 < data;
1017 return sizeof minus_infinity_string - 1; 1013 strcpy (buf, minus_infinity_string + positive);
1014 return sizeof minus_infinity_string - 1 - positive;
1018 } 1015 }
1019 /* Check for NaN in a way that won't fail if there are no NaNs. */ 1016#if IEEE_FLOATING_POINT
1020 if (! (data * 0.0 >= 0.0)) 1017 if (isnan (data))
1021 { 1018 {
1022 /* Prepend "-" if the NaN's sign bit is negative. 1019 union ieee754_double u = { .d = data };
1023 The sign bit of a double is the bit that is 1 in -0.0. */ 1020 uprintmax_t hi = u.ieee_nan.mantissa0;
1024 static char const NaN_string[] = "0.0e+NaN"; 1021 return sprintf (buf, &"-%"pMu".0e+NaN"[!u.ieee_nan.negative],
1025 int i; 1022 (hi << 31 << 1) + u.ieee_nan.mantissa1);
1026 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
1027 bool negative = 0;
1028 u_data.d = data;
1029 u_minus_zero.d = - 0.0;
1030 for (i = 0; i < sizeof (double); i++)
1031 if (u_data.c[i] & u_minus_zero.c[i])
1032 {
1033 *buf = '-';
1034 negative = 1;
1035 break;
1036 }
1037
1038 strcpy (buf + negative, NaN_string);
1039 return negative + sizeof NaN_string - 1;
1040 } 1023 }
1024#endif
1041 1025
1042 if (NILP (Vfloat_output_format) 1026 if (NILP (Vfloat_output_format)
1043 || !STRINGP (Vfloat_output_format)) 1027 || !STRINGP (Vfloat_output_format))