diff options
author | Paul Eggert <[email protected]> | 2011-04-19 23:26:24 -0700 |
---|---|---|
committer | Paul Eggert <[email protected]> | 2011-04-19 23:26:24 -0700 |
commit | b8e30af5f6f8f669a14318aa818a10e70553c821 (patch) | |
tree | d672146f839d481f55ca74eef18a338e4c713226 /src/data.c | |
parent | f2d3008d3ce90e30e347f184d6394f96f04dae3c (diff) | |
parent | 8b9587d73b579fb2fdd0eaaa1ed5fd608653e522 (diff) |
Merge: Make the Lisp reader and string-to-float more consistent.
Diffstat (limited to 'src/data.c')
-rw-r--r-- | src/data.c | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/src/data.c b/src/data.c index 8ece190524..486816cac7 100644 --- a/src/data.c +++ b/src/data.c @@ -48,10 +48,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <math.h> -#if !defined (atof) -extern double atof (const char *); -#endif /* !atof */ - Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound; static Lisp_Object Qsubr; Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; @@ -2410,8 +2406,7 @@ If the base used is not 10, STRING is always parsed as integer. */) { register char *p; register int b; - int sign = 1; - Lisp_Object val; + EMACS_INT n; CHECK_STRING (string); @@ -2425,38 +2420,23 @@ If the base used is not 10, STRING is always parsed as integer. */) xsignal1 (Qargs_out_of_range, base); } - /* Skip any whitespace at the front of the number. Some versions of - atoi do this anyway, so we might as well make Emacs lisp consistent. */ + /* Skip any whitespace at the front of the number. Typically strtol does + this anyway, so we might as well be consistent. */ p = SSDATA (string); while (*p == ' ' || *p == '\t') p++; - if (*p == '-') - { - sign = -1; - p++; - } - else if (*p == '+') - p++; - - if (isfloat_string (p, 1) && b == 10) - val = make_float (sign * atof (p)); - else + if (b == 10) { - double v = 0; - - while (1) - { - int digit = digit_to_number (*p++, b); - if (digit < 0) - break; - v = v * b + digit; - } - - val = make_fixnum_or_float (sign * v); + Lisp_Object val = string_to_float (p, 1); + if (FLOATP (val)) + return val; } - return val; + n = strtol (p, NULL, b); + if (FIXNUM_OVERFLOW_P (n)) + xsignal (Qoverflow_error, list1 (string)); + return make_number (n); } |