aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lobject.c b/lobject.c
index 0e504be0..301aa900 100644
--- a/lobject.c
+++ b/lobject.c
@@ -164,7 +164,7 @@ static int isneg (const char **s) {
164*/ 164*/
165static lua_Number lua_strx2number (const char *s, char **endptr) { 165static lua_Number lua_strx2number (const char *s, char **endptr) {
166 int dot = lua_getlocaledecpoint(); 166 int dot = lua_getlocaledecpoint();
167 lua_Number r = 0.0; /* result (accumulator) */ 167 lua_Number r = l_mathop(0.0); /* result (accumulator) */
168 int sigdig = 0; /* number of significant digits */ 168 int sigdig = 0; /* number of significant digits */
169 int nosigdig = 0; /* number of non-significant digits */ 169 int nosigdig = 0; /* number of non-significant digits */
170 int e = 0; /* exponent correction */ 170 int e = 0; /* exponent correction */
@@ -174,7 +174,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
174 while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ 174 while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
175 neg = isneg(&s); /* check sign */ 175 neg = isneg(&s); /* check sign */
176 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */ 176 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
177 return 0.0; /* invalid format (no '0x') */ 177 return l_mathop(0.0); /* invalid format (no '0x') */
178 for (s += 2; ; s++) { /* skip '0x' and read numeral */ 178 for (s += 2; ; s++) { /* skip '0x' and read numeral */
179 if (*s == dot) { 179 if (*s == dot) {
180 if (hasdot) break; /* second dot? stop loop */ 180 if (hasdot) break; /* second dot? stop loop */
@@ -184,14 +184,14 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
184 if (sigdig == 0 && *s == '0') /* non-significant digit (zero)? */ 184 if (sigdig == 0 && *s == '0') /* non-significant digit (zero)? */
185 nosigdig++; 185 nosigdig++;
186 else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */ 186 else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */
187 r = (r * cast_num(16.0)) + luaO_hexavalue(*s); 187 r = (r * l_mathop(16.0)) + luaO_hexavalue(*s);
188 else e++; /* too many digits; ignore, but still count for exponent */ 188 else e++; /* too many digits; ignore, but still count for exponent */
189 if (hasdot) e--; /* decimal digit? correct exponent */ 189 if (hasdot) e--; /* decimal digit? correct exponent */
190 } 190 }
191 else break; /* neither a dot nor a digit */ 191 else break; /* neither a dot nor a digit */
192 } 192 }
193 if (nosigdig + sigdig == 0) /* no digits? */ 193 if (nosigdig + sigdig == 0) /* no digits? */
194 return 0.0; /* invalid format */ 194 return l_mathop(0.0); /* invalid format */
195 *endptr = cast_charp(s); /* valid up to here */ 195 *endptr = cast_charp(s); /* valid up to here */
196 e *= 4; /* each digit multiplies/divides value by 2^4 */ 196 e *= 4; /* each digit multiplies/divides value by 2^4 */
197 if (*s == 'p' || *s == 'P') { /* exponent part? */ 197 if (*s == 'p' || *s == 'P') { /* exponent part? */
@@ -200,7 +200,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
200 s++; /* skip 'p' */ 200 s++; /* skip 'p' */
201 neg1 = isneg(&s); /* sign */ 201 neg1 = isneg(&s); /* sign */
202 if (!lisdigit(cast_uchar(*s))) 202 if (!lisdigit(cast_uchar(*s)))
203 return 0.0; /* invalid; must have at least one digit */ 203 return l_mathop(0.0); /* invalid; must have at least one digit */
204 while (lisdigit(cast_uchar(*s))) /* read exponent */ 204 while (lisdigit(cast_uchar(*s))) /* read exponent */
205 exp1 = exp1 * 10 + *(s++) - '0'; 205 exp1 = exp1 * 10 + *(s++) - '0';
206 if (neg1) exp1 = -exp1; 206 if (neg1) exp1 = -exp1;