diff --git a/lua.stx b/lua.stx index 79b94e7f..61939628 100644 --- a/lua.stx +++ b/lua.stx @@ -1,6 +1,6 @@ %{ -char *rcs_luastx = "$Id: lua.stx,v 3.41 1996/11/08 12:49:35 roberto Exp roberto $"; +char *rcs_luastx = "$Id: lua.stx,v 3.42 1997/01/15 16:11:37 roberto Exp roberto $"; #include #include @@ -163,9 +163,9 @@ static void add_varbuffer (Long var) static void code_number (float f) { - Word i = (Word)f; - if (f == (float)i) /* f has an (short) integer value */ - { + Word i; + if (f >= 0 && f <= (float)MAX_WORD && (float)(i=(Word)f) == f) { + /* f has an (short) integer value */ if (i <= 2) code_byte(PUSH0 + i); else if (i <= 255) { diff --git a/opcode.c b/opcode.c index 0df045a0..5c03d7b5 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.77 1996/11/18 13:48:44 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.78 1996/11/22 13:08:28 roberto Exp roberto $"; #include #include @@ -157,16 +157,20 @@ static int lua_tonumber (Object *obj) */ static int lua_tostring (Object *obj) { - char s[256]; - if (tag(obj) != LUA_T_NUMBER) - return 1; - if ((int) nvalue(obj) == nvalue(obj)) - sprintf (s, "%d", (int) nvalue(obj)); - else - sprintf (s, "%g", nvalue(obj)); - tsvalue(obj) = lua_createstring(s); - tag(obj) = LUA_T_STRING; - return 0; + if (tag(obj) != LUA_T_NUMBER) + return 1; + else { + char s[60]; + real f = nvalue(obj); + int i; + if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) + sprintf (s, "%d", i); + else + sprintf (s, "%g", nvalue(obj)); + tsvalue(obj) = lua_createstring(s); + tag(obj) = LUA_T_STRING; + return 0; + } }