* configure.ac: Check for ieee754.h.
* doc/lispref/numbers.texi (Float Basics): Document
that NaN string representation digits are machine-dependent.
* etc/NEWS: Mention the change.
* src/lread.c, src/print.c [HAVE_IEEE754_H]: Include ieee754.h.
* src/lread.c (string_to_number) [HAVE_IEEE754_H]:
* src/print.c (float_to_string) [HAVE_IEEE754_H]:
Read and print NaN significand.
dnl checks for header files
AC_CHECK_HEADERS_ONCE(
+ ieee754.h
linux/fs.h
malloc.h
sys/systeminfo.h
NaNs carry a sign and a significand, and non-numeric functions treat
two NaNs as equal when their
signs and significands agree. Significands of NaNs are
-machine-dependent and are not directly visible to Emacs Lisp.
+machine-dependent, as are the digits in their string representation.
When NaNs and signed zeros are involved, non-numeric functions like
@code{eql}, @code{equal}, @code{sxhash-eql}, @code{sxhash-equal} and
NaNs. Now, all these functions treat NaN signs and significands as
significant. For example, (eql 0.0e+NaN -0.0e+NaN) now returns nil
because the two NaNs have different signs; formerly it returned t.
+Also, on platforms that have <ieee754.h> Emacs now reads and prints
+NaN significands; e.g., if X is a NaN, (format "%s" X) now returns
+"0.0e+NaN", "1.0e+NaN", etc., depending on X's significand.
+++
** The function 'make-string' accepts an additional optional argument.
#define file_tell ftell
#endif
+#if HAVE_IEEE754_H
+# include <ieee754.h>
+#endif
+
/* The objects or placeholders read with the #n=object form.
A hash table maps a number to either a placeholder (while the
{
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
}
else
cp = ecp;
#include <ftoastr.h>
#include <math.h>
+#if HAVE_IEEE754_H
+# include <ieee754.h>
+#endif
+
#ifdef WINDOWSNT
# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */
#endif
}
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";
strcpy (buf + negative, NaN_string);
return negative + sizeof NaN_string - 1;
+#endif
}
if (NILP (Vfloat_output_format)