diff options
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.28 1999/12/23 18:19:57 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.29 1999/12/30 18:28:40 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 | */ |
@@ -87,9 +87,9 @@ int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ | |||
87 | int point = 0; /* number of decimal digits */ | 87 | int point = 0; /* number of decimal digits */ |
88 | int sig; | 88 | int sig; |
89 | while (isspace((unsigned char)*s)) s++; | 89 | while (isspace((unsigned char)*s)) s++; |
90 | sig = 1; | 90 | sig = 0; |
91 | switch (*s) { | 91 | switch (*s) { |
92 | case '-': sig = -1; /* go through */ | 92 | case '-': sig = 1; /* go through */ |
93 | case '+': s++; | 93 | case '+': s++; |
94 | } | 94 | } |
95 | if (! (isdigit((unsigned char)*s) || | 95 | if (! (isdigit((unsigned char)*s) || |
@@ -104,20 +104,21 @@ int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ | |||
104 | point++; | 104 | point++; |
105 | } | 105 | } |
106 | } | 106 | } |
107 | a *= sig; | 107 | if (sig) a = -a; |
108 | if (toupper((unsigned char)*s) == 'E') { | 108 | if (*s == 'e' || *s == 'E') { |
109 | int e = 0; | 109 | int e = 0; |
110 | s++; | 110 | s++; |
111 | sig = 1; | 111 | sig = 0; |
112 | switch (*s) { | 112 | switch (*s) { |
113 | case '-': sig = -1; /* go through */ | 113 | case '-': sig = 1; /* go through */ |
114 | case '+': s++; | 114 | case '+': s++; |
115 | } | 115 | } |
116 | if (!isdigit((unsigned char)*s)) return 0; /* no digit in the exponent? */ | 116 | if (!isdigit((unsigned char)*s)) return 0; /* no digit in the exponent? */ |
117 | do { | 117 | do { |
118 | e = 10*e + (*(s++)-'0'); | 118 | e = 10*e + (*(s++)-'0'); |
119 | } while (isdigit((unsigned char)*s)); | 119 | } while (isdigit((unsigned char)*s)); |
120 | point -= sig*e; | 120 | if (sig) e = -e; |
121 | point -= e; | ||
121 | } | 122 | } |
122 | while (isspace((unsigned char)*s)) s++; | 123 | while (isspace((unsigned char)*s)) s++; |
123 | if (*s != '\0') return 0; /* invalid trailing characters? */ | 124 | if (*s != '\0') return 0; /* invalid trailing characters? */ |