summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1998-02-02 01:08:52 +0000
committerRichard M. Stallman <rms@gnu.org>1998-02-02 01:08:52 +0000
commit0899df6189fdf4c2363897c239df9242e4231166 (patch)
tree465179bfe7f2512068fb1a439e6543d89437bf78
parent0af9c46f8ded26cd8702fe63c07e3d0a2157f2ec (diff)
downloademacs-0899df6189fdf4c2363897c239df9242e4231166.tar.gz
(read1): Handle infinities, NaN and -0.0 specially.
(isfloat_string): Accept e+INF and e+NAN as exponents.
-rw-r--r--src/lread.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/lread.c b/src/lread.c
index ef46e5f6a34..ec72ded41ba 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1907,7 +1907,23 @@ read1 (readcharfun, pch, first_in_list)
}
#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 @@ isfloat_string (cp)
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)