math_exp是lua标准库函数math.exp的具体实现。math_exp声明如下:
static int math_exp (lua_State *L);
math_exp接受一个参数,将其命名为n;math_exp的目的是求科学常数e(e=2.718281828459…)的n次幂,用数学公式可表示为: $$ e^{n} $$
math_exp的源代码:
static int math_exp (lua_State *L) {
lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));
return 1;
}
math_exp的实现非常地简单:先将传入参数转换成lua_Number类型的实数n,然后将实数n传递给C标准库函数exp;由exp求得e的n次幂;将exp求得的结果入栈。