several functions deprecated (cosh, sinh, atanh, pow, frexp, ldexp)

This commit is contained in:
Roberto Ierusalimschy 2014-05-14 13:59:27 -03:00
parent 965993da07
commit 8b66040e34
1 changed files with 72 additions and 66 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lmathlib.c,v 1.98 2014/04/17 16:09:40 roberto Exp roberto $ ** $Id: lmathlib.c,v 1.99 2014/05/02 16:36:51 roberto Exp roberto $
** Standard mathematical library ** Standard mathematical library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -48,31 +48,16 @@ static int math_sin (lua_State *L) {
return 1; return 1;
} }
static int math_sinh (lua_State *L) {
lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_cos (lua_State *L) { static int math_cos (lua_State *L) {
lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1))); lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int math_cosh (lua_State *L) {
lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_tan (lua_State *L) { static int math_tan (lua_State *L) {
lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1))); lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int math_tanh (lua_State *L) {
lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_asin (lua_State *L) { static int math_asin (lua_State *L) {
lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1))); lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));
return 1; return 1;
@ -84,13 +69,9 @@ static int math_acos (lua_State *L) {
} }
static int math_atan (lua_State *L) { static int math_atan (lua_State *L) {
lua_pushnumber(L, l_mathop(atan)(luaL_checknumber(L, 1))); lua_Number y = luaL_checknumber(L, 1);
return 1; lua_Number x = luaL_optnumber(L, 2, 1);
} lua_pushnumber(L, l_mathop(atan2)(y, x));
static int math_atan2 (lua_State *L) {
lua_pushnumber(L, l_mathop(atan2)(luaL_checknumber(L, 1),
luaL_checknumber(L, 2)));
return 1; return 1;
} }
@ -153,13 +134,6 @@ static int math_sqrt (lua_State *L) {
return 1; return 1;
} }
static int math_pow (lua_State *L) {
lua_Number x = luaL_checknumber(L, 1);
lua_Number y = luaL_checknumber(L, 2);
lua_pushnumber(L, l_mathop(pow)(x, y));
return 1;
}
static int math_log (lua_State *L) { static int math_log (lua_State *L) {
lua_Number x = luaL_checknumber(L, 1); lua_Number x = luaL_checknumber(L, 1);
lua_Number res; lua_Number res;
@ -174,13 +148,6 @@ static int math_log (lua_State *L) {
return 1; return 1;
} }
#if defined(LUA_COMPAT_LOG10)
static int math_log10 (lua_State *L) {
lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));
return 1;
}
#endif
static int math_exp (lua_State *L) { static int math_exp (lua_State *L) {
lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1))); lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));
return 1; return 1;
@ -196,38 +163,24 @@ static int math_rad (lua_State *L) {
return 1; return 1;
} }
static int math_frexp (lua_State *L) {
int e;
lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));
lua_pushinteger(L, e);
return 2;
}
static int math_ldexp (lua_State *L) {
lua_Number x = luaL_checknumber(L, 1);
int ep = luaL_checkint(L, 2);
lua_pushnumber(L, l_mathop(ldexp)(x, ep));
return 1;
}
static int math_min (lua_State *L) { static int math_min (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
int imax = 1; int imin = 1; /* index of current minimum value */
int i; int i;
luaL_argcheck(L, n >= 1, 1, "value expected"); luaL_argcheck(L, n >= 1, 1, "value expected");
for (i = 2; i <= n; i++) { for (i = 2; i <= n; i++) {
if (lua_compare(L, i, imax, LUA_OPLT)) if (lua_compare(L, i, imin, LUA_OPLT))
imax = i; imin = i;
} }
lua_pushvalue(L, imax); lua_pushvalue(L, imin);
return 1; return 1;
} }
static int math_max (lua_State *L) { static int math_max (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
int imax = 1; int imax = 1; /* index of current maximum value */
int i; int i;
luaL_argcheck(L, n >= 1, 1, "value expected"); luaL_argcheck(L, n >= 1, 1, "value expected");
for (i = 2; i <= n; i++) { for (i = 2; i <= n; i++) {
@ -294,39 +247,92 @@ static int math_type (lua_State *L) {
} }
/*
** {==================================================================
** Deprecated functions (for compatibility only)
** ===================================================================
*/
#if defined(LUA_COMPAT_MATHLIB)
static int math_cosh (lua_State *L) {
lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_sinh (lua_State *L) {
lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_tanh (lua_State *L) {
lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_pow (lua_State *L) {
lua_Number x = luaL_checknumber(L, 1);
lua_Number y = luaL_checknumber(L, 2);
lua_pushnumber(L, l_mathop(pow)(x, y));
return 1;
}
static int math_frexp (lua_State *L) {
int e;
lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));
lua_pushinteger(L, e);
return 2;
}
static int math_ldexp (lua_State *L) {
lua_Number x = luaL_checknumber(L, 1);
int ep = luaL_checkint(L, 2);
lua_pushnumber(L, l_mathop(ldexp)(x, ep));
return 1;
}
static int math_log10 (lua_State *L) {
lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));
return 1;
}
#endif
/* }================================================================== */
static const luaL_Reg mathlib[] = { static const luaL_Reg mathlib[] = {
{"abs", math_abs}, {"abs", math_abs},
{"acos", math_acos}, {"acos", math_acos},
{"asin", math_asin}, {"asin", math_asin},
{"atan2", math_atan2},
{"atan", math_atan}, {"atan", math_atan},
{"ceil", math_ceil}, {"ceil", math_ceil},
{"cosh", math_cosh},
{"cos", math_cos}, {"cos", math_cos},
{"deg", math_deg}, {"deg", math_deg},
{"exp", math_exp}, {"exp", math_exp},
{"floor", math_floor}, {"floor", math_floor},
{"ifloor", math_ifloor}, {"ifloor", math_ifloor},
{"fmod", math_fmod}, {"fmod", math_fmod},
{"frexp", math_frexp},
{"ldexp", math_ldexp},
#if defined(LUA_COMPAT_LOG10)
{"log10", math_log10},
#endif
{"log", math_log}, {"log", math_log},
{"max", math_max}, {"max", math_max},
{"min", math_min}, {"min", math_min},
{"modf", math_modf}, {"modf", math_modf},
{"pow", math_pow},
{"rad", math_rad}, {"rad", math_rad},
{"random", math_random}, {"random", math_random},
{"randomseed", math_randomseed}, {"randomseed", math_randomseed},
{"sinh", math_sinh},
{"sin", math_sin}, {"sin", math_sin},
{"sqrt", math_sqrt}, {"sqrt", math_sqrt},
{"tanh", math_tanh},
{"tan", math_tan}, {"tan", math_tan},
{"type", math_type}, {"type", math_type},
#if defined(LUA_COMPAT_MATHLIB)
{"atan2", math_atan},
{"cosh", math_cosh},
{"sinh", math_sinh},
{"tanh", math_tanh},
{"pow", math_pow},
{"frexp", math_frexp},
{"ldexp", math_ldexp},
{"log10", math_log10},
#endif
{NULL, NULL} {NULL, NULL}
}; };