summaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-13 17:09:04 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-13 17:09:04 -0200
commitfb663f768d6d19bdbf6c2ef800657a027a126c24 (patch)
tree2c9d9cfb1cb685e76f94665a6022eab3932f1218 /lvm.c
parente03767b3eb45059ef9a367161154bec407d78f35 (diff)
downloadlua-fb663f768d6d19bdbf6c2ef800657a027a126c24.tar.gz
lua-fb663f768d6d19bdbf6c2ef800657a027a126c24.tar.bz2
lua-fb663f768d6d19bdbf6c2ef800657a027a126c24.zip
"%.16g" already formats integers as integers, so we do not need an
alternative "%ld" convertion in "tostring".
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/lvm.c b/lvm.c
index c1995034..8f64f9f5 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.36 1998/12/30 17:26:49 roberto Exp roberto $ 2** $Id: lvm.c,v 1.37 1999/01/12 18:38:35 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -51,8 +51,7 @@ static TaggedString *strconc (TaggedString *l, TaggedString *r) {
51} 51}
52 52
53 53
54int luaV_tonumber (TObject *obj) { 54int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
55 /* LUA_NUMBER */
56 if (ttype(obj) != LUA_T_STRING) 55 if (ttype(obj) != LUA_T_STRING)
57 return 1; 56 return 1;
58 else { 57 else {
@@ -74,18 +73,12 @@ int luaV_tonumber (TObject *obj) {
74} 73}
75 74
76 75
77int luaV_tostring (TObject *obj) { 76int luaV_tostring (TObject *obj) { /* LUA_NUMBER */
78 /* LUA_NUMBER */
79 if (ttype(obj) != LUA_T_NUMBER) 77 if (ttype(obj) != LUA_T_NUMBER)
80 return 1; 78 return 1;
81 else { 79 else {
82 char s[60]; 80 char s[32]; /* 16 digits, signal, point and \0 (+ some extra...) */
83 real f = nvalue(obj); 81 sprintf(s, "%.16g", (double)nvalue(obj));
84 long i;
85 if ((real)LONG_MIN <= f && f <= (real)LONG_MAX && (real)(i=(long)f) == f)
86 sprintf(s, "%ld", i);
87 else
88 sprintf(s, "%.15g", (double)nvalue(obj));
89 tsvalue(obj) = luaS_new(s); 82 tsvalue(obj) = luaS_new(s);
90 ttype(obj) = LUA_T_STRING; 83 ttype(obj) = LUA_T_STRING;
91 return 0; 84 return 0;