summaryrefslogtreecommitdiff
path: root/src/lmathlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lmathlib.c')
-rw-r--r--src/lmathlib.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/lmathlib.c b/src/lmathlib.c
index add88970..bba99b0d 100644
--- a/src/lmathlib.c
+++ b/src/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.62 2005/01/07 20:00:33 roberto Exp $
+** $Id: lmathlib.c,v 1.63 2005/03/04 18:57:03 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -33,16 +33,31 @@ static int math_sin (lua_State *L) {
return 1;
}
+static int math_sinh (lua_State *L) {
+ lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
+ return 1;
+}
+
static int math_cos (lua_State *L) {
lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
return 1;
}
+static int math_cosh (lua_State *L) {
+ lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
+ return 1;
+}
+
static int math_tan (lua_State *L) {
lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
return 1;
}
+static int math_tanh (lua_State *L) {
+ lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
+ return 1;
+}
+
static int math_asin (lua_State *L) {
lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
return 1;
@@ -78,6 +93,14 @@ static int math_mod (lua_State *L) {
return 1;
}
+static int math_modf (lua_State *L) {
+ double ip;
+ double fp = modf(luaL_checknumber(L, 1), &ip);
+ lua_pushnumber(L, ip);
+ lua_pushnumber(L, fp);
+ return 2;
+}
+
static int math_sqrt (lua_State *L) {
lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
return 1;
@@ -192,8 +215,11 @@ static int math_randomseed (lua_State *L) {
static const luaL_reg mathlib[] = {
{"abs", math_abs},
{"sin", math_sin},
+ {"sinh", math_sinh},
{"cos", math_cos},
+ {"cosh", math_cosh},
{"tan", math_tan},
+ {"tanh", math_tanh},
{"asin", math_asin},
{"acos", math_acos},
{"atan", math_atan},
@@ -201,6 +227,7 @@ static const luaL_reg mathlib[] = {
{"ceil", math_ceil},
{"floor", math_floor},
{"mod", math_mod},
+ {"modf", math_modf},
{"frexp", math_frexp},
{"ldexp", math_ldexp},
{"sqrt", math_sqrt},
@@ -225,6 +252,8 @@ LUALIB_API int luaopen_math (lua_State *L) {
luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0);
lua_pushnumber(L, PI);
lua_setfield(L, -2, "pi");
+ lua_pushnumber(L, HUGE_VAL);
+ lua_setfield(L, -2, "huge");
return 1;
}