aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-05-10 15:11:32 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-05-10 15:11:32 -0300
commita17dd24b34cdbf2fd88773c743f6086059d8a272 (patch)
tree576bf8b5c1ecd75b4b18c76ecaea347371668094 /lmathlib.c
parentb072e4ea0ba72a78712f9a10f25c7266f906d5c5 (diff)
downloadlua-a17dd24b34cdbf2fd88773c743f6086059d8a272.tar.gz
lua-a17dd24b34cdbf2fd88773c743f6086059d8a272.tar.bz2
lua-a17dd24b34cdbf2fd88773c743f6086059d8a272.zip
no more USE_DEGREES option
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/lmathlib.c b/lmathlib.c
index 76809b53..9da84f3e 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.59 2003/11/05 11:59:14 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.60 2004/04/30 20:13:38 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -23,56 +23,43 @@
23 23
24 24
25 25
26/*
27** If you want Lua to operate in degrees (instead of radians),
28** define USE_DEGREES
29*/
30#ifdef USE_DEGREES
31#define FROMRAD(a) ((a)/RADIANS_PER_DEGREE)
32#define TORAD(a) ((a)*RADIANS_PER_DEGREE)
33#else
34#define FROMRAD(a) (a)
35#define TORAD(a) (a)
36#endif
37
38
39static int math_abs (lua_State *L) { 26static int math_abs (lua_State *L) {
40 lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); 27 lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
41 return 1; 28 return 1;
42} 29}
43 30
44static int math_sin (lua_State *L) { 31static int math_sin (lua_State *L) {
45 lua_pushnumber(L, sin(TORAD(luaL_checknumber(L, 1)))); 32 lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
46 return 1; 33 return 1;
47} 34}
48 35
49static int math_cos (lua_State *L) { 36static int math_cos (lua_State *L) {
50 lua_pushnumber(L, cos(TORAD(luaL_checknumber(L, 1)))); 37 lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
51 return 1; 38 return 1;
52} 39}
53 40
54static int math_tan (lua_State *L) { 41static int math_tan (lua_State *L) {
55 lua_pushnumber(L, tan(TORAD(luaL_checknumber(L, 1)))); 42 lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
56 return 1; 43 return 1;
57} 44}
58 45
59static int math_asin (lua_State *L) { 46static int math_asin (lua_State *L) {
60 lua_pushnumber(L, FROMRAD(asin(luaL_checknumber(L, 1)))); 47 lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
61 return 1; 48 return 1;
62} 49}
63 50
64static int math_acos (lua_State *L) { 51static int math_acos (lua_State *L) {
65 lua_pushnumber(L, FROMRAD(acos(luaL_checknumber(L, 1)))); 52 lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
66 return 1; 53 return 1;
67} 54}
68 55
69static int math_atan (lua_State *L) { 56static int math_atan (lua_State *L) {
70 lua_pushnumber(L, FROMRAD(atan(luaL_checknumber(L, 1)))); 57 lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
71 return 1; 58 return 1;
72} 59}
73 60
74static int math_atan2 (lua_State *L) { 61static int math_atan2 (lua_State *L) {
75 lua_pushnumber(L, FROMRAD(atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)))); 62 lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
76 return 1; 63 return 1;
77} 64}
78 65