aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/lmathlib.c b/lmathlib.c
index b030f97e..2f0f3d1b 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -38,31 +38,37 @@ static int math_abs (lua_State *L) {
38 return 1; 38 return 1;
39} 39}
40 40
41
41static int math_sin (lua_State *L) { 42static int math_sin (lua_State *L) {
42 lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1))); 43 lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));
43 return 1; 44 return 1;
44} 45}
45 46
47
46static int math_cos (lua_State *L) { 48static int math_cos (lua_State *L) {
47 lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1))); 49 lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));
48 return 1; 50 return 1;
49} 51}
50 52
53
51static int math_tan (lua_State *L) { 54static int math_tan (lua_State *L) {
52 lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1))); 55 lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));
53 return 1; 56 return 1;
54} 57}
55 58
59
56static int math_asin (lua_State *L) { 60static int math_asin (lua_State *L) {
57 lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1))); 61 lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));
58 return 1; 62 return 1;
59} 63}
60 64
65
61static int math_acos (lua_State *L) { 66static int math_acos (lua_State *L) {
62 lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1))); 67 lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));
63 return 1; 68 return 1;
64} 69}
65 70
71
66static int math_atan (lua_State *L) { 72static int math_atan (lua_State *L) {
67 lua_Number y = luaL_checknumber(L, 1); 73 lua_Number y = luaL_checknumber(L, 1);
68 lua_Number x = luaL_optnumber(L, 2, 1); 74 lua_Number x = luaL_optnumber(L, 2, 1);
@@ -167,6 +173,7 @@ static int math_ult (lua_State *L) {
167 return 1; 173 return 1;
168} 174}
169 175
176
170static int math_log (lua_State *L) { 177static int math_log (lua_State *L) {
171 lua_Number x = luaL_checknumber(L, 1); 178 lua_Number x = luaL_checknumber(L, 1);
172 lua_Number res; 179 lua_Number res;
@@ -188,28 +195,34 @@ static int math_log (lua_State *L) {
188 return 1; 195 return 1;
189} 196}
190 197
198
191static int math_exp (lua_State *L) { 199static int math_exp (lua_State *L) {
192 lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1))); 200 lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));
193 return 1; 201 return 1;
194} 202}
195 203
204
196static int math_deg (lua_State *L) { 205static int math_deg (lua_State *L) {
197 lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI)); 206 lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI));
198 return 1; 207 return 1;
199} 208}
200 209
210
201static int math_rad (lua_State *L) { 211static int math_rad (lua_State *L) {
202 lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0))); 212 lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0)));
203 return 1; 213 return 1;
204} 214}
205 215
216
206static int math_frexp (lua_State *L) { 217static int math_frexp (lua_State *L) {
207 int e; 218 lua_Number x = luaL_checknumber(L, 1);
208 lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e)); 219 int ep;
209 lua_pushinteger(L, e); 220 lua_pushnumber(L, l_mathop(frexp)(x, &ep));
221 lua_pushinteger(L, ep);
210 return 2; 222 return 2;
211} 223}
212 224
225
213static int math_ldexp (lua_State *L) { 226static int math_ldexp (lua_State *L) {
214 lua_Number x = luaL_checknumber(L, 1); 227 lua_Number x = luaL_checknumber(L, 1);
215 int ep = (int)luaL_checkinteger(L, 2); 228 int ep = (int)luaL_checkinteger(L, 2);