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')
This commit is contained in:
Roberto Ierusalimschy 2013-05-26 10:45:24 -03:00
parent 3563b3f519
commit 1414b7123c
1 changed files with 7 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.84 2013/05/02 17:31:54 roberto Exp roberto $
** $Id: lmathlib.c,v 1.85 2013/05/06 17:22:55 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@ -22,6 +22,11 @@
#define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0))
/* types for lua_Number pointers subject to 'l_mathop' changes */
typedef float l_pnumf;
typedef double l_pnum;
typedef long double l_pnuml;
static int math_abs (lua_State *L) {
lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));
@ -96,7 +101,7 @@ static int math_fmod (lua_State *L) {
}
static int math_modf (lua_State *L) {
lua_Number ip;
l_mathop(l_pnum) ip;
lua_Number fp = l_mathop(modf)(luaL_checknumber(L, 1), &ip);
lua_pushnumber(L, ip);
lua_pushnumber(L, fp);