diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-08 11:28:04 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-08 11:28:04 -0300 |
commit | c7859a046ded0eaca74a4412b03fc657d6d9ab4d (patch) | |
tree | 7bd6bf21c451ee04c24141d67b3c5433a01539f6 /lvm.c | |
parent | 4a248836746a0942c6f923ad0265c87ba85a3d35 (diff) | |
download | lua-c7859a046ded0eaca74a4412b03fc657d6d9ab4d.tar.gz lua-c7859a046ded0eaca74a4412b03fc657d6d9ab4d.tar.bz2 lua-c7859a046ded0eaca74a4412b03fc657d6d9ab4d.zip |
using 'volatile' in 'tofloat' to ensure result has the same precision
(lua_Number) of other computations
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.192 2014/03/31 19:18:24 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.193 2014/04/02 16:54:20 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 | */ |
@@ -38,12 +38,15 @@ | |||
38 | 38 | ||
39 | 39 | ||
40 | /* | 40 | /* |
41 | ** Similar to 'tonumber', but does not attempt to convert strings. | 41 | ** Similar to 'tonumber', but does not attempt to convert strings and |
42 | ** Used in comparisons. | 42 | ** ensure correct precision (no extra bits). Used in comparisons. |
43 | */ | 43 | */ |
44 | static int tofloat (const TValue *obj, lua_Number *n) { | 44 | static int tofloat (const TValue *obj, lua_Number *n) { |
45 | if (ttisfloat(obj)) *n = fltvalue(obj); | 45 | if (ttisfloat(obj)) *n = fltvalue(obj); |
46 | else if (ttisinteger(obj)) *n = cast_num(ivalue(obj)); | 46 | else if (ttisinteger(obj)) { |
47 | volatile lua_Number x = cast_num(ivalue(obj)); /* avoid extra precision */ | ||
48 | *n = x; | ||
49 | } | ||
47 | else { | 50 | else { |
48 | *n = 0; /* to avoid warnings */ | 51 | *n = 0; /* to avoid warnings */ |
49 | return 0; | 52 | return 0; |