diff options
| -rw-r--r-- | lobject.c | 18 | ||||
| -rw-r--r-- | lvm.c | 9 |
2 files changed, 15 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.17 1999/02/12 19:23:02 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.18 1999/02/26 15:48:30 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 | */ |
| @@ -93,25 +93,25 @@ static double expten (unsigned int e) { | |||
| 93 | double luaO_str2d (char *s) { /* LUA_NUMBER */ | 93 | double luaO_str2d (char *s) { /* LUA_NUMBER */ |
| 94 | double a = 0.0; | 94 | double a = 0.0; |
| 95 | int point = 0; | 95 | int point = 0; |
| 96 | if (!isdigit((unsigned char)*s) && !isdigit((unsigned char)*(s+1))) | ||
| 97 | return -1; /* no digit before or after decimal point */ | ||
| 98 | while (isdigit((unsigned char)*s)) { | 96 | while (isdigit((unsigned char)*s)) { |
| 99 | a = 10.0*a + (*(s++)-'0'); | 97 | a = 10.0*a + (*(s++)-'0'); |
| 100 | } | 98 | } |
| 101 | if (*s == '.') s++; | 99 | if (*s == '.') { |
| 102 | while (isdigit((unsigned char)*s)) { | 100 | s++; |
| 103 | a = 10.0*a + (*(s++)-'0'); | 101 | while (isdigit((unsigned char)*s)) { |
| 104 | point++; | 102 | a = 10.0*a + (*(s++)-'0'); |
| 103 | point++; | ||
| 104 | } | ||
| 105 | } | 105 | } |
| 106 | if (toupper((unsigned char)*s) == 'E') { | 106 | if (toupper((unsigned char)*s) == 'E') { |
| 107 | int e = 0; | 107 | int e = 0; |
| 108 | int sig = 1; | 108 | int sig = 1; |
| 109 | s++; | 109 | s++; |
| 110 | if (*s == '+') s++; | 110 | if (*s == '-') { |
| 111 | else if (*s == '-') { | ||
| 112 | s++; | 111 | s++; |
| 113 | sig = -1; | 112 | sig = -1; |
| 114 | } | 113 | } |
| 114 | else if (*s == '+') s++; | ||
| 115 | if (!isdigit((unsigned char)*s)) return -1; /* no digit in the exponent? */ | 115 | if (!isdigit((unsigned char)*s)) return -1; /* no digit in the exponent? */ |
| 116 | do { | 116 | do { |
| 117 | e = 10*e + (*(s++)-'0'); | 117 | e = 10*e + (*(s++)-'0'); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.53 1999/03/05 21:16:07 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.54 1999/03/10 14:09:45 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -57,11 +57,14 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */ | |||
| 57 | char *e = svalue(obj); | 57 | char *e = svalue(obj); |
| 58 | int sig = 1; | 58 | int sig = 1; |
| 59 | while (isspace((unsigned char)*e)) e++; | 59 | while (isspace((unsigned char)*e)) e++; |
| 60 | if (*e == '+') e++; | 60 | if (*e == '-') { |
| 61 | else if (*e == '-') { | ||
| 62 | e++; | 61 | e++; |
| 63 | sig = -1; | 62 | sig = -1; |
| 64 | } | 63 | } |
| 64 | else if (*e == '+') e++; | ||
| 65 | /* no digit before or after decimal point? */ | ||
| 66 | if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1))) | ||
| 67 | return 2; | ||
| 65 | t = luaO_str2d(e); | 68 | t = luaO_str2d(e); |
| 66 | if (t<0) return 2; | 69 | if (t<0) return 2; |
| 67 | nvalue(obj) = (real)t*sig; | 70 | nvalue(obj) = (real)t*sig; |
