1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00

correct support for changing real to double (optional)

This commit is contained in:
Roberto Ierusalimschy 1997-07-31 16:37:37 -03:00
parent caa987faad
commit a7793468aa
2 changed files with 15 additions and 16 deletions

4
lex.c
View File

@ -1,4 +1,4 @@
char *rcs_lex = "$Id: lex.c,v 3.7 1997/07/29 13:33:15 roberto Exp roberto $"; char *rcs_lex = "$Id: lex.c,v 3.8 1997/07/30 22:00:50 roberto Exp roberto $";
#include <ctype.h> #include <ctype.h>
@ -432,7 +432,7 @@ int luaY_lex (void)
ea*=ea; ea*=ea;
} }
} }
luaY_lval.vFloat = a; luaY_lval.vReal = a;
save(0); save(0);
return NUMBER; return NUMBER;
} }

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
*/ */
char *rcs_opcode="$Id: opcode.c,v 4.19 1997/07/29 21:11:10 roberto Exp roberto $"; char *rcs_opcode="$Id: opcode.c,v 4.20 1997/07/30 22:00:50 roberto Exp roberto $";
#include <setjmp.h> #include <setjmp.h>
#include <stdio.h> #include <stdio.h>
@ -141,13 +141,12 @@ static char *lua_strconc (char *l, char *r)
*/ */
static int lua_tonumber (TObject *obj) static int lua_tonumber (TObject *obj)
{ {
float t; double t;
char c; char c;
if (ttype(obj) != LUA_T_STRING) if (ttype(obj) != LUA_T_STRING)
return 1; return 1;
else if (sscanf(svalue(obj), "%f %c",&t, &c) == 1) else if (sscanf(svalue(obj), "%lf %c",&t, &c) == 1) {
{ nvalue(obj) = (real)t;
nvalue(obj) = t;
ttype(obj) = LUA_T_NUMBER; ttype(obj) = LUA_T_NUMBER;
return 0; return 0;
} }
@ -171,7 +170,7 @@ static int lua_tostring (TObject *obj)
if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f)
sprintf (s, "%d", i); sprintf (s, "%d", i);
else else
sprintf (s, "%g", nvalue(obj)); sprintf (s, "%g", (double)nvalue(obj));
tsvalue(obj) = luaI_createstring(s); tsvalue(obj) = luaI_createstring(s);
ttype(obj) = LUA_T_STRING; ttype(obj) = LUA_T_STRING;
return 0; return 0;