Commit 2f700871 authored by Paul Eggert's avatar Paul Eggert

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.
parent 23717173
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.
......
......@@ -28,6 +28,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#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"
......@@ -3369,10 +3370,6 @@ string_to_number (char const *string, int base, bool ignore_trailing)
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. */
......@@ -3424,30 +3421,15 @@ string_to_number (char const *string, int base, bool ignore_trailing)
{
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment