diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-05-26 10:45:24 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-05-26 10:45:24 -0300 |
| commit | 1414b7123ca46f7e133ee71400e8ed7f95187c47 (patch) | |
| tree | 88aac810cbc6dcf6d2a75bee191b920cba800dcd | |
| parent | 3563b3f51942da0cc0360394476b3910b51ebdd9 (diff) | |
| download | lua-1414b7123ca46f7e133ee71400e8ed7f95187c47.tar.gz lua-1414b7123ca46f7e133ee71400e8ed7f95187c47.tar.bz2 lua-1414b7123ca46f7e133ee71400e8ed7f95187c47.zip | |
support for the case when 'l_mathop' does not conform to lua_Number
(problem with pointers to lua_Number solved by a typedef selected
automatically by 'l_mathop')
| -rw-r--r-- | lmathlib.c | 9 |
1 files changed, 7 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.84 2013/05/02 17:31:54 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.85 2013/05/06 17:22:55 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 | */ |
| @@ -22,6 +22,11 @@ | |||
| 22 | #define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0)) | 22 | #define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0)) |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | /* types for lua_Number pointers subject to 'l_mathop' changes */ | ||
| 26 | typedef float l_pnumf; | ||
| 27 | typedef double l_pnum; | ||
| 28 | typedef long double l_pnuml; | ||
| 29 | |||
| 25 | 30 | ||
| 26 | static int math_abs (lua_State *L) { | 31 | static int math_abs (lua_State *L) { |
| 27 | lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1))); | 32 | lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1))); |
| @@ -96,7 +101,7 @@ static int math_fmod (lua_State *L) { | |||
| 96 | } | 101 | } |
| 97 | 102 | ||
| 98 | static int math_modf (lua_State *L) { | 103 | static int math_modf (lua_State *L) { |
| 99 | lua_Number ip; | 104 | l_mathop(l_pnum) ip; |
| 100 | lua_Number fp = l_mathop(modf)(luaL_checknumber(L, 1), &ip); | 105 | lua_Number fp = l_mathop(modf)(luaL_checknumber(L, 1), &ip); |
| 101 | lua_pushnumber(L, ip); | 106 | lua_pushnumber(L, ip); |
| 102 | lua_pushnumber(L, fp); | 107 | lua_pushnumber(L, fp); |
