aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorGerd Moellmann2000-02-23 12:50:35 +0000
committerGerd Moellmann2000-02-23 12:50:35 +0000
commit342858a566fc88254094fb8f67ecc8ad72a139e9 (patch)
tree2ea29837ef0434548b9c8051e65ea428479f6ce5 /src/data.c
parentb6906b38425a06651575a033d55e81776ef286c6 (diff)
downloademacs-342858a566fc88254094fb8f67ecc8ad72a139e9.tar.gz
emacs-342858a566fc88254094fb8f67ecc8ad72a139e9.zip
(Fstring_to_number): If number is greater than what
fits into an integer, return a float.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/data.c b/src/data.c
index f524b097df8..4de8b257a75 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2101,8 +2101,9 @@ If the base used is not 10, floating point is not recognized.")
2101 register Lisp_Object string, base; 2101 register Lisp_Object string, base;
2102{ 2102{
2103 register unsigned char *p; 2103 register unsigned char *p;
2104 register int b, v = 0; 2104 register int b;
2105 int negative = 1; 2105 int sign = 1;
2106 Lisp_Object val;
2106 2107
2107 CHECK_STRING (string, 0); 2108 CHECK_STRING (string, 0);
2108 2109
@@ -2116,33 +2117,41 @@ If the base used is not 10, floating point is not recognized.")
2116 Fsignal (Qargs_out_of_range, Fcons (base, Qnil)); 2117 Fsignal (Qargs_out_of_range, Fcons (base, Qnil));
2117 } 2118 }
2118 2119
2119 p = XSTRING (string)->data;
2120
2121 /* Skip any whitespace at the front of the number. Some versions of 2120 /* Skip any whitespace at the front of the number. Some versions of
2122 atoi do this anyway, so we might as well make Emacs lisp consistent. */ 2121 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2122 p = XSTRING (string)->data;
2123 while (*p == ' ' || *p == '\t') 2123 while (*p == ' ' || *p == '\t')
2124 p++; 2124 p++;
2125 2125
2126 if (*p == '-') 2126 if (*p == '-')
2127 { 2127 {
2128 negative = -1; 2128 sign = -1;
2129 p++; 2129 p++;
2130 } 2130 }
2131 else if (*p == '+') 2131 else if (*p == '+')
2132 p++; 2132 p++;
2133 2133
2134 if (isfloat_string (p) && b == 10) 2134 if (isfloat_string (p) && b == 10)
2135 return make_float (negative * atof (p)); 2135 val = make_float (sign * atof (p));
2136 2136 else
2137 while (1)
2138 { 2137 {
2139 int digit = digit_to_number (*p++, b); 2138 double v = 0;
2140 if (digit < 0) 2139
2141 break; 2140 while (1)
2142 v = v * b + digit; 2141 {
2142 int digit = digit_to_number (*p++, b);
2143 if (digit < 0)
2144 break;
2145 v = v * b + digit;
2146 }
2147
2148 if (v > (EMACS_UINT) (VALMASK >> 1))
2149 val = make_float (sign * v);
2150 else
2151 val = make_number (sign * (int) v);
2143 } 2152 }
2144 2153
2145 return make_number (negative * v); 2154 return val;
2146} 2155}
2147 2156
2148 2157