emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 2f70087: Use C99's INFINITY and NAN macros


From: Paul Eggert
Subject: [Emacs-diffs] master 2f70087: Use C99's INFINITY and NAN macros
Date: Mon, 09 Feb 2015 07:12:36 +0000

branch: master
commit 2f7008715326a49770fcb82003ed78eab28c0626
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    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.
---
 src/ChangeLog |    6 ++++++
 src/lread.c   |   26 ++++----------------------
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 3b2c9a6..381ae6b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
 2015-02-09  Paul Eggert  <address@hidden>
 
+       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.
diff --git a/src/lread.c b/src/lread.c
index 69ec059..b42849f 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]