diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-08-28 12:36:58 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-08-28 12:36:58 -0300 |
commit | 5382a22e0eea878339c504b2a9a3b36bcd839fcc (patch) | |
tree | f4208ffe221d2f42920c751c3624f17d89b07079 /lobject.c | |
parent | 8c8a91f2ef7acccb99e3737913faad8d48b39571 (diff) | |
download | lua-5382a22e0eea878339c504b2a9a3b36bcd839fcc.tar.gz lua-5382a22e0eea878339c504b2a9a3b36bcd839fcc.tar.bz2 lua-5382a22e0eea878339c504b2a9a3b36bcd839fcc.zip |
Corrections in the implementation of '%' for floats.
The multiplication (m*b) used to test whether 'm' is non-zero and
'm' and 'b' have different signs can underflow for very small numbers,
giving a wrong result. The use of explicit comparisons solves this
problem. This commit also adds several new tests for '%' (both for
floats and for integers) to exercise more corner cases, such as
very large and very small values.
Diffstat (limited to '')
-rw-r--r-- | lobject.c | 6 |
1 files changed, 1 insertions, 5 deletions
@@ -106,11 +106,7 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1, | |||
106 | case LUA_OPPOW: return luai_numpow(L, v1, v2); | 106 | case LUA_OPPOW: return luai_numpow(L, v1, v2); |
107 | case LUA_OPIDIV: return luai_numidiv(L, v1, v2); | 107 | case LUA_OPIDIV: return luai_numidiv(L, v1, v2); |
108 | case LUA_OPUNM: return luai_numunm(L, v1); | 108 | case LUA_OPUNM: return luai_numunm(L, v1); |
109 | case LUA_OPMOD: { | 109 | case LUA_OPMOD: return luaV_modf(L, v1, v2); |
110 | lua_Number m; | ||
111 | luai_nummod(L, v1, v2, m); | ||
112 | return m; | ||
113 | } | ||
114 | default: lua_assert(0); return 0; | 110 | default: lua_assert(0); return 0; |
115 | } | 111 | } |
116 | } | 112 | } |