TDengine/2.0/deps/lua/src/lmathlib.c

264 lines
5.7 KiB
C
Raw Normal View History

Hotfix/sangshuduo/m2d 20210702 (#6719) * [TD-4132]<test>: add taosdump-testcase of boundary value testing * [TD-3952]<test>: add taodemo-testcase that query with restful connector * merge master * modify taosdemo-testcase * add testcase of async subscirbe and max sql num * testcase-subscribe of super table * testcase-modify sub * modify subscribe testcase * [TD-4238]<test>: add taodemo-testcase that records of number in request sql less than 32767 * add taosdemo-subscribe-testcase * update taosdemo testcase * temp commit * temp commit * temp commit * temp1 * temp * [TD-4835] add lua lib * [TD-4369]<test>: add testcase of resubscibe * [TD-4826]<fix>: new error code 0x0406 (Dnode is exiting) for tsc * [TD-4369]<test>: add testcase of resubscibe and json file * temp * update master to develop's version * Update boundary2.py * [TD-4912]<hotfix>: fix coredump when drop vnode * Hotfix/sangshuduo/td 3801 taosdump coverity scan issue (#6642) * [TD-3801]<fix>: taosdump coverity scan issue. * merge from commit: 069169e7c1 and fix coverity scan issue. Co-authored-by: Shuduo Sang <sdsang@taosdata.com> * [TD-4932]fix jenkins errors on master branch (#6645) * [TD-4932]fix jenkins errors on master branch * fix * fix * fix * fix * [TD-4132]<test>:modify taosdump-testcase of column length * [TD-4918]<fix>: taosdemo subscribe endAfterResume. (#6653) * [TD-4915]<fix> fix show-create-database except * Hotfix/sangshuduo/td 4892 taosdemo sub fetch (#6669) * [TD-4892]<fix>: taosdemo subscribe fetch result. * fix stbname length. * restrict prefix length. * submit empty * fix minor code. * fix crash if no result file. * decrease few debug print level. * fix offset issue * [TD-4987]<fix>: issues memory sanitizier detected. (#6675) * [TD-4826]<fix>: no extra sleep if no message in vwqueue * [TD-4593]<fix>: fix vnode cannnot close while syncing * Hotfix/sangshuduo/td 4918 taosdemo sub afterconsume (#6685) * [TD-4918]<fix>: taosdemo subscribe endAfterResume. * fix mask length. * fix heap use-after-free. * Hotfix/sangshuduo/td 4987 detected by mem sanitizer (#6684) * [TD-4987]<fix>: issues memory sanitizier detected. * fix mask width issue. * [TD-4828]<fix> handle dnode exit code * Hotfix/sangshuduo/td 3973 use jemalloc for master (#6702) * [TD-3973]<feature>: add jemalloc as submodule. * [TD-3973]<feature>: add jemalloc as submodule. * [TD-3973]<feature>: use jemalloc. build works as following instructions: cmake .. -DJEMALLOC_ENABLED=true make * fix jemalloc at tag 5.2.1 * fix conflicts * make install works. * fix conflicts. * release script works. * fix typo Co-authored-by: Shuduo Sang <sdsang@taosdata.com> * TD-4835 * only compile in lua * [td-4748]<fix>:fix the temp file generate buf on windows platform. * change cmake options * [TD-5007]<fix>: use build directory's taosdump to test. (#6710) btw, solve two taosdemo test cases too. * Hotfix/sangshuduo/td 4838 taosdump binary len bug (#6713) * [TD-4838]<fix>: taosdump binary length bug. * taosdump code refactoring. * fix arm32 compile issue. Co-authored-by: tomchon <haoran920c@163.com> Co-authored-by: Shengliang Guan <slguan@taosdata.com> Co-authored-by: Minglei Jin <mljin@taosdata.com> Co-authored-by: Baosheng Chang <changb9@mcmaster.ca> Co-authored-by: Hongze Cheng <hzcheng@taosdata.com> Co-authored-by: Shuduo Sang <sdsang@taosdata.com> Co-authored-by: Yiqing Liu <yqliu@taosdata.com> Co-authored-by: Hui Li <52318143+plum-lihui@users.noreply.github.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com> Co-authored-by: wpan <wpan@taosdata.com> Co-authored-by: Haojun Liao <hjxilinx@users.noreply.github.com> Co-authored-by: Haojun Liao <hjliao@taosdata.com>
2021-07-02 09:31:12 +00:00
/*
** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
#include <stdlib.h>
#include <math.h>
#define lmathlib_c
#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#undef PI
#define PI (3.14159265358979323846)
#define RADIANS_PER_DEGREE (PI/180.0)
static int math_abs (lua_State *L) {
lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
return 1;
}
static int math_sin (lua_State *L) {
lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
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;
}
static int math_acos (lua_State *L) {
lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
return 1;
}
static int math_atan (lua_State *L) {
lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
return 1;
}
static int math_atan2 (lua_State *L) {
lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1;
}
static int math_ceil (lua_State *L) {
lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
return 1;
}
static int math_floor (lua_State *L) {
lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
return 1;
}
static int math_fmod (lua_State *L) {
lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
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;
}
static int math_pow (lua_State *L) {
lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1;
}
static int math_log (lua_State *L) {
lua_pushnumber(L, log(luaL_checknumber(L, 1)));
return 1;
}
static int math_log10 (lua_State *L) {
lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
return 1;
}
static int math_exp (lua_State *L) {
lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
return 1;
}
static int math_deg (lua_State *L) {
lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
return 1;
}
static int math_rad (lua_State *L) {
lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
return 1;
}
static int math_frexp (lua_State *L) {
int e;
lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
lua_pushinteger(L, e);
return 2;
}
static int math_ldexp (lua_State *L) {
lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
return 1;
}
static int math_min (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
lua_Number dmin = luaL_checknumber(L, 1);
int i;
for (i=2; i<=n; i++) {
lua_Number d = luaL_checknumber(L, i);
if (d < dmin)
dmin = d;
}
lua_pushnumber(L, dmin);
return 1;
}
static int math_max (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
lua_Number dmax = luaL_checknumber(L, 1);
int i;
for (i=2; i<=n; i++) {
lua_Number d = luaL_checknumber(L, i);
if (d > dmax)
dmax = d;
}
lua_pushnumber(L, dmax);
return 1;
}
static int math_random (lua_State *L) {
/* the `%' avoids the (rare) case of r==1, and is needed also because on
some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
switch (lua_gettop(L)) { /* check number of arguments */
case 0: { /* no arguments */
lua_pushnumber(L, r); /* Number between 0 and 1 */
break;
}
case 1: { /* only upper limit */
int u = luaL_checkint(L, 1);
luaL_argcheck(L, 1<=u, 1, "interval is empty");
lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */
break;
}
case 2: { /* lower and upper limits */
int l = luaL_checkint(L, 1);
int u = luaL_checkint(L, 2);
luaL_argcheck(L, l<=u, 2, "interval is empty");
lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */
break;
}
default: return luaL_error(L, "wrong number of arguments");
}
return 1;
}
static int math_randomseed (lua_State *L) {
srand(luaL_checkint(L, 1));
return 0;
}
static const luaL_Reg mathlib[] = {
{"abs", math_abs},
{"acos", math_acos},
{"asin", math_asin},
{"atan2", math_atan2},
{"atan", math_atan},
{"ceil", math_ceil},
{"cosh", math_cosh},
{"cos", math_cos},
{"deg", math_deg},
{"exp", math_exp},
{"floor", math_floor},
{"fmod", math_fmod},
{"frexp", math_frexp},
{"ldexp", math_ldexp},
{"log10", math_log10},
{"log", math_log},
{"max", math_max},
{"min", math_min},
{"modf", math_modf},
{"pow", math_pow},
{"rad", math_rad},
{"random", math_random},
{"randomseed", math_randomseed},
{"sinh", math_sinh},
{"sin", math_sin},
{"sqrt", math_sqrt},
{"tanh", math_tanh},
{"tan", math_tan},
{NULL, NULL}
};
/*
** Open math library
*/
LUALIB_API int luaopen_math (lua_State *L) {
luaL_register(L, LUA_MATHLIBNAME, mathlib);
lua_pushnumber(L, PI);
lua_setfield(L, -2, "pi");
lua_pushnumber(L, HUGE_VAL);
lua_setfield(L, -2, "huge");
#if defined(LUA_COMPAT_MOD)
lua_getfield(L, -1, "fmod");
lua_setfield(L, -2, "mod");
#endif
return 1;
}