aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-28 16:41:38 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-28 16:41:38 -0200
commit59fbbf0a65d4729b65adf07b4d8b4770495cc9b8 (patch)
tree7aca29d7435bcc4c76e70016cf4f1e4753e82639 /lobject.c
parent61c3c80177de00576620d79d586eb57d8723ee1a (diff)
downloadlua-59fbbf0a65d4729b65adf07b4d8b4770495cc9b8.tar.gz
lua-59fbbf0a65d4729b65adf07b4d8b4770495cc9b8.tar.bz2
lua-59fbbf0a65d4729b65adf07b4d8b4770495cc9b8.zip
small simplifications in code for 'lua_strx2number'
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/lobject.c b/lobject.c
index e805ce66..78f71179 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.95 2014/10/25 11:50:46 roberto Exp roberto $ 2** $Id: lobject.c,v 2.96 2014/10/27 19:21:56 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -162,8 +162,13 @@ static int isneg (const char **s) {
162} 162}
163 163
164 164
165/* Lua's implementation for 'lua_strx2number' */ 165
166#if !defined(lua_strx2number) /* { */ 166/*
167** {==================================================================
168** Lua's implementation for 'lua_strx2number'
169** ===================================================================
170*/
171#if !defined(lua_strx2number)
167 172
168#include <math.h> 173#include <math.h>
169 174
@@ -193,18 +198,12 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
193 else dot = 1; 198 else dot = 1;
194 } 199 }
195 else if (lisxdigit(cast_uchar(*s))) { 200 else if (lisxdigit(cast_uchar(*s))) {
196 if (sigdig == 0 && *s == '0') { /* non-significant zero? */ 201 if (sigdig == 0 && *s == '0') /* non-significant digit (zero)? */
197 nosigdig++; 202 nosigdig++;
198 if (dot) e--; /* zero after dot? correct exponent */ 203 else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */
199 }
200 else {
201 if (++sigdig <= MAXSIGDIG) { /* can read it without overflow? */
202 r = (r * cast_num(16.0)) + luaO_hexavalue(cast_uchar(*s)); 204 r = (r * cast_num(16.0)) + luaO_hexavalue(cast_uchar(*s));
203 if (dot) e--; /* decimal digit */ 205 else e++; /* too many digits; ignore, but still count for exponent */
204 } 206 if (dot) e--; /* decimal digit? correct exponent */
205 else /* too many digits; ignore */
206 if (!dot) e++; /* still count it for exponent */
207 }
208 } 207 }
209 else break; /* neither a dot nor a digit */ 208 else break; /* neither a dot nor a digit */
210 } 209 }
@@ -229,8 +228,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
229 return l_mathop(ldexp)(r, e); 228 return l_mathop(ldexp)(r, e);
230} 229}
231 230
232#endif /* } */ 231#endif
233
234/* }====================================================== */ 232/* }====================================================== */
235 233
236 234