lua

A copy of the Lua development repository
Log | Files | Refs | README

commit a7793468aa61cf2b9aad8c18c0f88632eab5577b
parent caa987faad6191a2abaf9d2741216ba619359fdb
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Thu, 31 Jul 1997 16:37:16 -0300

correct support for changing real to double (optional)

Diffstat:
Mlex.c | 4++--
Mopcode.c | 27+++++++++++++--------------
2 files changed, 15 insertions(+), 16 deletions(-)

diff --git 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 <ctype.h> @@ -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 @@ -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 <setjmp.h> #include <stdio.h> @@ -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;