diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-31 16:37:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-31 16:37:37 -0300 |
commit | a7793468aa61cf2b9aad8c18c0f88632eab5577b (patch) | |
tree | c95e9c2d48344830131d76d116503fdfa1b76291 /opcode.c | |
parent | caa987faad6191a2abaf9d2741216ba619359fdb (diff) | |
download | lua-a7793468aa61cf2b9aad8c18c0f88632eab5577b.tar.gz lua-a7793468aa61cf2b9aad8c18c0f88632eab5577b.tar.bz2 lua-a7793468aa61cf2b9aad8c18c0f88632eab5577b.zip |
correct support for changing real to double (optional)
Diffstat (limited to 'opcode.c')
-rw-r--r-- | opcode.c | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 4.19 1997/07/29 21:11:10 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 4.20 1997/07/30 22:00:50 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -141,18 +141,17 @@ static char *lua_strconc (char *l, char *r) | |||
141 | */ | 141 | */ |
142 | static int lua_tonumber (TObject *obj) | 142 | static int lua_tonumber (TObject *obj) |
143 | { | 143 | { |
144 | float t; | 144 | double t; |
145 | char c; | 145 | char c; |
146 | if (ttype(obj) != LUA_T_STRING) | 146 | if (ttype(obj) != LUA_T_STRING) |
147 | return 1; | 147 | return 1; |
148 | else if (sscanf(svalue(obj), "%f %c",&t, &c) == 1) | 148 | else if (sscanf(svalue(obj), "%lf %c",&t, &c) == 1) { |
149 | { | 149 | nvalue(obj) = (real)t; |
150 | nvalue(obj) = t; | 150 | ttype(obj) = LUA_T_NUMBER; |
151 | ttype(obj) = LUA_T_NUMBER; | 151 | return 0; |
152 | return 0; | 152 | } |
153 | } | 153 | else |
154 | else | 154 | return 2; |
155 | return 2; | ||
156 | } | 155 | } |
157 | 156 | ||
158 | 157 | ||
@@ -171,7 +170,7 @@ static int lua_tostring (TObject *obj) | |||
171 | if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) | 170 | if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) |
172 | sprintf (s, "%d", i); | 171 | sprintf (s, "%d", i); |
173 | else | 172 | else |
174 | sprintf (s, "%g", nvalue(obj)); | 173 | sprintf (s, "%g", (double)nvalue(obj)); |
175 | tsvalue(obj) = luaI_createstring(s); | 174 | tsvalue(obj) = luaI_createstring(s); |
176 | ttype(obj) = LUA_T_STRING; | 175 | ttype(obj) = LUA_T_STRING; |
177 | return 0; | 176 | return 0; |