From a7793468aa61cf2b9aad8c18c0f88632eab5577b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 31 Jul 1997 16:37:37 -0300 Subject: [PATCH] correct support for changing real to double (optional) --- lex.c | 4 ++-- opcode.c | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lex.c b/lex.c index 81cbe527..59588d19 100644 --- a/lex.c +++ b/lex.c @@ -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 @@ -432,7 +432,7 @@ int luaY_lex (void) ea*=ea; } } - luaY_lval.vFloat = a; + luaY_lval.vReal = a; save(0); return NUMBER; } diff --git a/opcode.c b/opcode.c index 505e6c45..a5ade2cf 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** 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 #include @@ -141,18 +141,17 @@ static char *lua_strconc (char *l, char *r) */ static int lua_tonumber (TObject *obj) { - float t; - char c; - if (ttype(obj) != LUA_T_STRING) - return 1; - else if (sscanf(svalue(obj), "%f %c",&t, &c) == 1) - { - nvalue(obj) = t; - ttype(obj) = LUA_T_NUMBER; - return 0; - } - else - return 2; + double t; + char c; + if (ttype(obj) != LUA_T_STRING) + return 1; + else if (sscanf(svalue(obj), "%lf %c",&t, &c) == 1) { + nvalue(obj) = (real)t; + ttype(obj) = LUA_T_NUMBER; + return 0; + } + else + return 2; } @@ -171,7 +170,7 @@ static int lua_tostring (TObject *obj) if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) sprintf (s, "%d", i); else - sprintf (s, "%g", nvalue(obj)); + sprintf (s, "%g", (double)nvalue(obj)); tsvalue(obj) = luaI_createstring(s); ttype(obj) = LUA_T_STRING; return 0;