aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorPaul Eggert2011-04-19 23:26:24 -0700
committerPaul Eggert2011-04-19 23:26:24 -0700
commitb8e30af5f6f8f669a14318aa818a10e70553c821 (patch)
treed672146f839d481f55ca74eef18a338e4c713226 /src/data.c
parentf2d3008d3ce90e30e347f184d6394f96f04dae3c (diff)
parent8b9587d73b579fb2fdd0eaaa1ed5fd608653e522 (diff)
downloademacs-b8e30af5f6f8f669a14318aa818a10e70553c821.tar.gz
emacs-b8e30af5f6f8f669a14318aa818a10e70553c821.zip
Merge: Make the Lisp reader and string-to-float more consistent.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c42
1 files changed, 11 insertions, 31 deletions
diff --git a/src/data.c b/src/data.c
index 8ece1905243..486816cac70 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/>. */
48 48
49#include <math.h> 49#include <math.h>
50 50
51#if !defined (atof)
52extern double atof (const char *);
53#endif /* !atof */
54
55Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound; 51Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
56static Lisp_Object Qsubr; 52static Lisp_Object Qsubr;
57Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; 53Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
@@ -2410,8 +2406,7 @@ If the base used is not 10, STRING is always parsed as integer. */)
2410{ 2406{
2411 register char *p; 2407 register char *p;
2412 register int b; 2408 register int b;
2413 int sign = 1; 2409 EMACS_INT n;
2414 Lisp_Object val;
2415 2410
2416 CHECK_STRING (string); 2411 CHECK_STRING (string);
2417 2412
@@ -2425,38 +2420,23 @@ If the base used is not 10, STRING is always parsed as integer. */)
2425 xsignal1 (Qargs_out_of_range, base); 2420 xsignal1 (Qargs_out_of_range, base);
2426 } 2421 }
2427 2422
2428 /* Skip any whitespace at the front of the number. Some versions of 2423 /* Skip any whitespace at the front of the number. Typically strtol does
2429 atoi do this anyway, so we might as well make Emacs lisp consistent. */ 2424 this anyway, so we might as well be consistent. */
2430 p = SSDATA (string); 2425 p = SSDATA (string);
2431 while (*p == ' ' || *p == '\t') 2426 while (*p == ' ' || *p == '\t')
2432 p++; 2427 p++;
2433 2428
2434 if (*p == '-') 2429 if (b == 10)
2435 {
2436 sign = -1;
2437 p++;
2438 }
2439 else if (*p == '+')
2440 p++;
2441
2442 if (isfloat_string (p, 1) && b == 10)
2443 val = make_float (sign * atof (p));
2444 else
2445 { 2430 {
2446 double v = 0; 2431 Lisp_Object val = string_to_float (p, 1);
2447 2432 if (FLOATP (val))
2448 while (1) 2433 return val;
2449 {
2450 int digit = digit_to_number (*p++, b);
2451 if (digit < 0)
2452 break;
2453 v = v * b + digit;
2454 }
2455
2456 val = make_fixnum_or_float (sign * v);
2457 } 2434 }
2458 2435
2459 return val; 2436 n = strtol (p, NULL, b);
2437 if (FIXNUM_OVERFLOW_P (n))
2438 xsignal (Qoverflow_error, list1 (string));
2439 return make_number (n);
2460} 2440}
2461 2441
2462 2442