Mercurial > emacs
changeset 27826:1a0a62bd23c4
(Fstring_to_number): If number is greater than what
fits into an integer, return a float.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Wed, 23 Feb 2000 12:50:35 +0000 |
parents | 8dc35300521c |
children | 25e4e0c9c19a |
files | src/data.c |
diffstat | 1 files changed, 23 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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; }