diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-10-08 16:57:31 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-10-08 16:57:31 -0300 |
commit | 65ec3379b10654f49b7faaf841b308b0cbb7b68b (patch) | |
tree | 7e8acbb37ec5f38c018b2fd35270d419d562f3d1 /lmathlib.c | |
parent | 85fc9ecd5f5d2af63d48f6ac2bb46217e3fa6a04 (diff) | |
download | lua-65ec3379b10654f49b7faaf841b308b0cbb7b68b.tar.gz lua-65ec3379b10654f49b7faaf841b308b0cbb7b68b.tar.bz2 lua-65ec3379b10654f49b7faaf841b308b0cbb7b68b.zip |
added some casts for the cases when lua_Number != double
Diffstat (limited to 'lmathlib.c')
-rw-r--r-- | lmathlib.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.108 2014/07/28 17:35:47 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.109 2014/10/01 11:54:56 roberto Exp $ |
3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -153,7 +153,7 @@ static int math_modf (lua_State *L) { | |||
153 | lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); | 153 | lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); |
154 | pushnumint(L, ip); | 154 | pushnumint(L, ip); |
155 | /* fractional part (test needed for inf/-inf) */ | 155 | /* fractional part (test needed for inf/-inf) */ |
156 | lua_pushnumber(L, (n == ip) ? 0.0 : (n - ip)); | 156 | lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip)); |
157 | } | 157 | } |
158 | return 2; | 158 | return 2; |
159 | } | 159 | } |
@@ -192,12 +192,12 @@ static int math_exp (lua_State *L) { | |||
192 | } | 192 | } |
193 | 193 | ||
194 | static int math_deg (lua_State *L) { | 194 | static int math_deg (lua_State *L) { |
195 | lua_pushnumber(L, luaL_checknumber(L, 1) * (180.0 / PI)); | 195 | lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI)); |
196 | return 1; | 196 | return 1; |
197 | } | 197 | } |
198 | 198 | ||
199 | static int math_rad (lua_State *L) { | 199 | static int math_rad (lua_State *L) { |
200 | lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / 180.0)); | 200 | lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0))); |
201 | return 1; | 201 | return 1; |
202 | } | 202 | } |
203 | 203 | ||
@@ -239,7 +239,7 @@ static int math_random (lua_State *L) { | |||
239 | double r = (double)l_rand() * (1.0 / ((double)RAND_MAX + 1.0)); | 239 | double r = (double)l_rand() * (1.0 / ((double)RAND_MAX + 1.0)); |
240 | switch (lua_gettop(L)) { /* check number of arguments */ | 240 | switch (lua_gettop(L)) { /* check number of arguments */ |
241 | case 0: { /* no arguments */ | 241 | case 0: { /* no arguments */ |
242 | lua_pushnumber(L, r); /* Number between 0 and 1 */ | 242 | lua_pushnumber(L, (lua_Number)r); /* Number between 0 and 1 */ |
243 | return 1; | 243 | return 1; |
244 | } | 244 | } |
245 | case 1: { /* only upper limit */ | 245 | case 1: { /* only upper limit */ |
@@ -389,7 +389,7 @@ LUAMOD_API int luaopen_math (lua_State *L) { | |||
389 | luaL_newlib(L, mathlib); | 389 | luaL_newlib(L, mathlib); |
390 | lua_pushnumber(L, PI); | 390 | lua_pushnumber(L, PI); |
391 | lua_setfield(L, -2, "pi"); | 391 | lua_setfield(L, -2, "pi"); |
392 | lua_pushnumber(L, HUGE_VAL); | 392 | lua_pushnumber(L, (lua_Number)HUGE_VAL); |
393 | lua_setfield(L, -2, "huge"); | 393 | lua_setfield(L, -2, "huge"); |
394 | lua_pushinteger(L, LUA_MAXINTEGER); | 394 | lua_pushinteger(L, LUA_MAXINTEGER); |
395 | lua_setfield(L, -2, "maxinteger"); | 395 | lua_setfield(L, -2, "maxinteger"); |