changeset 20815:d5ae7491d2b0

(read1): Handle infinities, NaN and -0.0 specially. (isfloat_string): Accept e+INF and e+NAN as exponents.
author Richard M. Stallman <rms@gnu.org>
date Mon, 02 Feb 1998 01:08:52 +0000
parents 8f6d92b4f48a
children 6397d7a97277
files src/lread.c
diffstat 1 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lread.c	Mon Feb 02 01:06:29 1998 +0000
+++ b/src/lread.c	Mon Feb 02 01:08:52 1998 +0000
@@ -1907,7 +1907,23 @@
 	      }
 #ifdef LISP_FLOAT_TYPE
 	    if (isfloat_string (read_buffer))
-	      return make_float (atof (read_buffer));
+	      {
+		double value = atof (read_buffer);
+		if (read_buffer[0] == '-' && value == 0.0)
+		  value *= -1.0;
+		/* The only way this can be true, after isfloat_string
+		   returns 1, is if the input ends in e+INF or e+NaN.  */
+		if (p[-1] == 'F' || p[-1] == 'N')
+		  {
+		    if (p[-1] == 'N')
+		      value = 0.0 / 0.0;
+		    else if (read_buffer[0] == '-')
+		      value = -1.0e999;
+		    else
+		      value = 1.0e999;
+		  }
+		return make_float (value);
+	      }
 #endif
 	  }
 
@@ -1968,6 +1984,17 @@
       while (*cp >= '0' && *cp <= '9')
 	cp++;
     }
+  else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
+    {
+      state |= EXP_INT;
+      cp += 3;
+    }
+  else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
+    {
+      state |= EXP_INT;
+      cp += 3;
+    }
+
   return (((*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
 	  && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
 	      || state == (DOT_CHAR|TRAIL_INT)