[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Missing math functions
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 18 Jan 2013 15:38:38 +0200
There's no math.asinh, math.acosh, math.atanh.
The reason presumably being that ANSI C does not provide
them.
But if your C compiler provides it, you may find the included
file useful.
/* invhyp.c (c) Dirk Laurie 2013 MIT license like Lua
* compile on Linux with
* cc -shared invhyp.c -o invhyp.so
* Then
* lua -l invhyp
* gives you a math library with asinh, acosh, atanh
*/
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include <math.h>
#include <stdio.h>
static int math_acosh (lua_State *L) {
lua_pushnumber(L, acosh(luaL_checknumber(L, 1)));
return 1;
}
static int math_asinh (lua_State *L) {
double x=luaL_checknumber(L, 1);
printf("%.16g -> ",x);
x=asinh(x);
printf("%.16g\n",x);
lua_pushnumber(L, x);
return 1;
}
static int math_atanh (lua_State *L) {
lua_pushnumber(L, atanh(luaL_checknumber(L, 1)));
return 1;
}
LUAMOD_API int luaopen_invhyp (lua_State *L) {
lua_getglobal(L,"math");
lua_pushstring(L,"asinh");
lua_pushcfunction(L,math_asinh);
lua_settable(L,-3);
lua_pushstring(L,"acosh");
lua_pushcfunction(L,math_acosh);
lua_settable(L,-3);
lua_pushstring(L,"atanh");
lua_pushcfunction(L,math_atanh);
lua_settable(L,-3);
return 1;
}