# HG changeset patch # User Gerd Moellmann # Date 951310235 0 # Node ID 1a0a62bd23c4b52603a6d01f9ebc3638fe39f1fd # Parent 8dc35300521c1a2fd7bb8cde7266c2bbc5097a91 (Fstring_to_number): If number is greater than what fits into an integer, return a float. diff -r 8dc35300521c -r 1a0a62bd23c4 src/data.c --- a/src/data.c Wed Feb 23 12:34:34 2000 +0000 +++ b/src/data.c Wed Feb 23 12:50:35 2000 +0000 @@ -2101,8 +2101,9 @@ register Lisp_Object string, base; { register unsigned char *p; - register int b, v = 0; - int negative = 1; + register int b; + int sign = 1; + Lisp_Object val; CHECK_STRING (string, 0); @@ -2116,33 +2117,41 @@ Fsignal (Qargs_out_of_range, Fcons (base, Qnil)); } - p = XSTRING (string)->data; - /* 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. */ + p = XSTRING (string)->data; while (*p == ' ' || *p == '\t') p++; if (*p == '-') { - negative = -1; + sign = -1; p++; } else if (*p == '+') p++; if (isfloat_string (p) && b == 10) - return make_float (negative * atof (p)); - - while (1) + val = make_float (sign * atof (p)); + else { - int digit = digit_to_number (*p++, b); - if (digit < 0) - break; - v = v * b + digit; + double v = 0; + + while (1) + { + int digit = digit_to_number (*p++, b); + if (digit < 0) + break; + v = v * b + digit; + } + + if (v > (EMACS_UINT) (VALMASK >> 1)) + val = make_float (sign * v); + else + val = make_number (sign * (int) v); } - - return make_number (negative * v); + + return val; }