aboutsummaryrefslogtreecommitdiff
path: root/mathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-06 11:08:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-06 11:08:08 -0300
commit3a9516ffc8de0d33051f83dc786dba615d6bac49 (patch)
tree9608796ca5abb4a724d70d99cb34dd818eb95662 /mathlib.c
parent42fa305649199712aad1c96beadb944b01277e3f (diff)
downloadlua-3a9516ffc8de0d33051f83dc786dba615d6bac49.tar.gz
lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.tar.bz2
lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.zip
luaL check functions do not need the function name (it can be
accessed via luadebug interface).
Diffstat (limited to 'mathlib.c')
-rw-r--r--mathlib.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/mathlib.c b/mathlib.c
index 7a74fe14..1774f7aa 100644
--- a/mathlib.c
+++ b/mathlib.c
@@ -3,7 +3,7 @@
3** Mathematics library to LUA 3** Mathematics library to LUA
4*/ 4*/
5 5
6char *rcs_mathlib="$Id: mathlib.c,v 1.21 1997/03/21 18:37:28 roberto Exp roberto $"; 6char *rcs_mathlib="$Id: mathlib.c,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <math.h> 9#include <math.h>
@@ -20,7 +20,7 @@ char *rcs_mathlib="$Id: mathlib.c,v 1.21 1997/03/21 18:37:28 roberto Exp roberto
20 20
21static void math_abs (void) 21static void math_abs (void)
22{ 22{
23 double d = luaL_check_number(1, "abs"); 23 double d = luaL_check_number(1);
24 if (d < 0) d = -d; 24 if (d < 0) d = -d;
25 lua_pushnumber (d); 25 lua_pushnumber (d);
26} 26}
@@ -28,7 +28,7 @@ static void math_abs (void)
28 28
29static void math_sin (void) 29static void math_sin (void)
30{ 30{
31 double d = luaL_check_number(1, "sin"); 31 double d = luaL_check_number(1);
32 lua_pushnumber (sin(TORAD(d))); 32 lua_pushnumber (sin(TORAD(d)));
33} 33}
34 34
@@ -36,7 +36,7 @@ static void math_sin (void)
36 36
37static void math_cos (void) 37static void math_cos (void)
38{ 38{
39 double d = luaL_check_number(1, "cos"); 39 double d = luaL_check_number(1);
40 lua_pushnumber (cos(TORAD(d))); 40 lua_pushnumber (cos(TORAD(d)));
41} 41}
42 42
@@ -44,82 +44,82 @@ static void math_cos (void)
44 44
45static void math_tan (void) 45static void math_tan (void)
46{ 46{
47 double d = luaL_check_number(1, "tan"); 47 double d = luaL_check_number(1);
48 lua_pushnumber (tan(TORAD(d))); 48 lua_pushnumber (tan(TORAD(d)));
49} 49}
50 50
51 51
52static void math_asin (void) 52static void math_asin (void)
53{ 53{
54 double d = luaL_check_number(1, "asin"); 54 double d = luaL_check_number(1);
55 lua_pushnumber (TODEGREE(asin(d))); 55 lua_pushnumber (TODEGREE(asin(d)));
56} 56}
57 57
58 58
59static void math_acos (void) 59static void math_acos (void)
60{ 60{
61 double d = luaL_check_number(1, "acos"); 61 double d = luaL_check_number(1);
62 lua_pushnumber (TODEGREE(acos(d))); 62 lua_pushnumber (TODEGREE(acos(d)));
63} 63}
64 64
65 65
66static void math_atan (void) 66static void math_atan (void)
67{ 67{
68 double d = luaL_check_number(1, "atan"); 68 double d = luaL_check_number(1);
69 lua_pushnumber (TODEGREE(atan(d))); 69 lua_pushnumber (TODEGREE(atan(d)));
70} 70}
71 71
72 72
73static void math_atan2 (void) 73static void math_atan2 (void)
74{ 74{
75 double d1 = luaL_check_number(1, "atan2"); 75 double d1 = luaL_check_number(1);
76 double d2 = luaL_check_number(2, "atan2"); 76 double d2 = luaL_check_number(2);
77 lua_pushnumber (TODEGREE(atan2(d1, d2))); 77 lua_pushnumber (TODEGREE(atan2(d1, d2)));
78} 78}
79 79
80 80
81static void math_ceil (void) 81static void math_ceil (void)
82{ 82{
83 double d = luaL_check_number(1, "ceil"); 83 double d = luaL_check_number(1);
84 lua_pushnumber (ceil(d)); 84 lua_pushnumber (ceil(d));
85} 85}
86 86
87 87
88static void math_floor (void) 88static void math_floor (void)
89{ 89{
90 double d = luaL_check_number(1, "floor"); 90 double d = luaL_check_number(1);
91 lua_pushnumber (floor(d)); 91 lua_pushnumber (floor(d));
92} 92}
93 93
94static void math_mod (void) 94static void math_mod (void)
95{ 95{
96 float x = luaL_check_number(1, "mod"); 96 float x = luaL_check_number(1);
97 float y = luaL_check_number(2, "mod"); 97 float y = luaL_check_number(2);
98 lua_pushnumber(fmod(x, y)); 98 lua_pushnumber(fmod(x, y));
99} 99}
100 100
101 101
102static void math_sqrt (void) 102static void math_sqrt (void)
103{ 103{
104 double d = luaL_check_number(1, "sqrt"); 104 double d = luaL_check_number(1);
105 lua_pushnumber (sqrt(d)); 105 lua_pushnumber (sqrt(d));
106} 106}
107 107
108 108
109static void math_pow (void) 109static void math_pow (void)
110{ 110{
111 double d1 = luaL_check_number(1, "exp"); 111 double d1 = luaL_check_number(1);
112 double d2 = luaL_check_number(2, "exp"); 112 double d2 = luaL_check_number(2);
113 lua_pushnumber(pow(d1,d2)); 113 lua_pushnumber(pow(d1,d2));
114} 114}
115 115
116static void math_min (void) 116static void math_min (void)
117{ 117{
118 int i=1; 118 int i=1;
119 double dmin = luaL_check_number(i, "min"); 119 double dmin = luaL_check_number(i);
120 while (lua_getparam(++i) != LUA_NOOBJECT) 120 while (lua_getparam(++i) != LUA_NOOBJECT)
121 { 121 {
122 double d = luaL_check_number(i, "min"); 122 double d = luaL_check_number(i);
123 if (d < dmin) dmin = d; 123 if (d < dmin) dmin = d;
124 } 124 }
125 lua_pushnumber (dmin); 125 lua_pushnumber (dmin);
@@ -128,10 +128,10 @@ static void math_min (void)
128static void math_max (void) 128static void math_max (void)
129{ 129{
130 int i=1; 130 int i=1;
131 double dmax = luaL_check_number(i, "max"); 131 double dmax = luaL_check_number(i);
132 while (lua_getparam(++i) != LUA_NOOBJECT) 132 while (lua_getparam(++i) != LUA_NOOBJECT)
133 { 133 {
134 double d = luaL_check_number(i, "max"); 134 double d = luaL_check_number(i);
135 if (d > dmax) dmax = d; 135 if (d > dmax) dmax = d;
136 } 136 }
137 lua_pushnumber (dmax); 137 lua_pushnumber (dmax);
@@ -139,33 +139,33 @@ static void math_max (void)
139 139
140static void math_log (void) 140static void math_log (void)
141{ 141{
142 double d = luaL_check_number(1, "log"); 142 double d = luaL_check_number(1);
143 lua_pushnumber (log(d)); 143 lua_pushnumber (log(d));
144} 144}
145 145
146 146
147static void math_log10 (void) 147static void math_log10 (void)
148{ 148{
149 double d = luaL_check_number(1, "log10"); 149 double d = luaL_check_number(1);
150 lua_pushnumber (log10(d)); 150 lua_pushnumber (log10(d));
151} 151}
152 152
153 153
154static void math_exp (void) 154static void math_exp (void)
155{ 155{
156 double d = luaL_check_number(1, "exp"); 156 double d = luaL_check_number(1);
157 lua_pushnumber (exp(d)); 157 lua_pushnumber (exp(d));
158} 158}
159 159
160static void math_deg (void) 160static void math_deg (void)
161{ 161{
162 float d = luaL_check_number(1, "deg"); 162 float d = luaL_check_number(1);
163 lua_pushnumber (d*180./PI); 163 lua_pushnumber (d*180./PI);
164} 164}
165 165
166static void math_rad (void) 166static void math_rad (void)
167{ 167{
168 float d = luaL_check_number(1, "rad"); 168 float d = luaL_check_number(1);
169 lua_pushnumber (d/180.*PI); 169 lua_pushnumber (d/180.*PI);
170} 170}
171 171
@@ -176,7 +176,7 @@ static void math_random (void)
176 176
177static void math_randomseed (void) 177static void math_randomseed (void)
178{ 178{
179 srand(luaL_check_number(1, "randomseed")); 179 srand(luaL_check_number(1));
180} 180}
181 181
182 182