2015-02-09 Paul Eggert <eggert@cs.ucla.edu>
+ Use C99's INFINITY and NAN macros
+ * lread.c: Include <math.h>.
+ (string_to_number): Use INFINITY and NAN rather than rolling our own.
+ This avoids some runtime diagnostics when building with
+ gcc -fsanitize=undefined.
+
Fix bidi_explicit_dir_char undefined behavior
* bidi.c (bidi_explicit_dir_char): Avoid subscript error when
argument is BIDI_EOB. This can happen in bidi_level_of_next_char.
#include <sys/file.h>
#include <errno.h>
#include <limits.h> /* For CHAR_BIT. */
+#include <math.h>
#include <stat-time.h>
#include "lisp.h"
#include "intervals.h"
bool float_syntax = 0;
double value = 0;
- /* Compute NaN and infinities using a variable, to cope with compilers that
- think they are smarter than we are. */
- double zero = 0;
-
/* Negate the value ourselves. This treats 0, NaNs, and infinity properly on
IEEE floating point hosts, and works around a formerly-common bug where
atof ("-0.0") drops the sign. */
{
state |= E_EXP;
cp += 3;
- value = 1.0 / zero;
+ value = INFINITY;
}
else if (cp[-1] == '+'
&& cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
{
state |= E_EXP;
cp += 3;
- value = zero / zero;
-
- /* If that made a "negative" NaN, negate it. */
- {
- int i;
- union { double d; char c[sizeof (double)]; }
- u_data, u_minus_zero;
- u_data.d = value;
- u_minus_zero.d = -0.0;
- for (i = 0; i < sizeof (double); i++)
- if (u_data.c[i] & u_minus_zero.c[i])
- {
- value = -value;
- break;
- }
- }
- /* Now VALUE is a positive NaN. */
+ /* NAN is a "positive" NaN on all known Emacs hosts. */
+ value = NAN;
}
else
cp = ecp;