diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-17 14:02:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-17 14:02:29 -0300 |
commit | eea734aa881002e90bd9130171a2b94cd9dc3267 (patch) | |
tree | b2816a614fca723d8c0b06e96cd093438e6e098b /mathlib.c | |
parent | b6d91e24e23edfe98ad732660fd456e91658edb9 (diff) | |
download | lua-eea734aa881002e90bd9130171a2b94cd9dc3267.tar.gz lua-eea734aa881002e90bd9130171a2b94cd9dc3267.tar.bz2 lua-eea734aa881002e90bd9130171a2b94cd9dc3267.zip |
new module 'auxlib' centralizes functions to get/check parameters.
Diffstat (limited to 'mathlib.c')
-rw-r--r-- | mathlib.c | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** Mathematics library to LUA | 3 | ** Mathematics library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_mathlib="$Id: mathlib.c,v 1.17 1996/04/30 21:13:55 roberto Exp roberto $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.18 1996/08/01 14:55:33 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <math.h> | 9 | #include <math.h> |
@@ -19,7 +19,7 @@ char *rcs_mathlib="$Id: mathlib.c,v 1.17 1996/04/30 21:13:55 roberto Exp roberto | |||
19 | 19 | ||
20 | static void math_abs (void) | 20 | static void math_abs (void) |
21 | { | 21 | { |
22 | double d = lua_check_number(1, "abs"); | 22 | double d = luaL_check_number(1, "abs"); |
23 | if (d < 0) d = -d; | 23 | if (d < 0) d = -d; |
24 | lua_pushnumber (d); | 24 | lua_pushnumber (d); |
25 | } | 25 | } |
@@ -27,7 +27,7 @@ static void math_abs (void) | |||
27 | 27 | ||
28 | static void math_sin (void) | 28 | static void math_sin (void) |
29 | { | 29 | { |
30 | double d = lua_check_number(1, "sin"); | 30 | double d = luaL_check_number(1, "sin"); |
31 | lua_pushnumber (sin(TORAD(d))); | 31 | lua_pushnumber (sin(TORAD(d))); |
32 | } | 32 | } |
33 | 33 | ||
@@ -35,7 +35,7 @@ static void math_sin (void) | |||
35 | 35 | ||
36 | static void math_cos (void) | 36 | static void math_cos (void) |
37 | { | 37 | { |
38 | double d = lua_check_number(1, "cos"); | 38 | double d = luaL_check_number(1, "cos"); |
39 | lua_pushnumber (cos(TORAD(d))); | 39 | lua_pushnumber (cos(TORAD(d))); |
40 | } | 40 | } |
41 | 41 | ||
@@ -43,64 +43,64 @@ static void math_cos (void) | |||
43 | 43 | ||
44 | static void math_tan (void) | 44 | static void math_tan (void) |
45 | { | 45 | { |
46 | double d = lua_check_number(1, "tan"); | 46 | double d = luaL_check_number(1, "tan"); |
47 | lua_pushnumber (tan(TORAD(d))); | 47 | lua_pushnumber (tan(TORAD(d))); |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | static void math_asin (void) | 51 | static void math_asin (void) |
52 | { | 52 | { |
53 | double d = lua_check_number(1, "asin"); | 53 | double d = luaL_check_number(1, "asin"); |
54 | lua_pushnumber (TODEGREE(asin(d))); | 54 | lua_pushnumber (TODEGREE(asin(d))); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | static void math_acos (void) | 58 | static void math_acos (void) |
59 | { | 59 | { |
60 | double d = lua_check_number(1, "acos"); | 60 | double d = luaL_check_number(1, "acos"); |
61 | lua_pushnumber (TODEGREE(acos(d))); | 61 | lua_pushnumber (TODEGREE(acos(d))); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | static void math_atan (void) | 65 | static void math_atan (void) |
66 | { | 66 | { |
67 | double d = lua_check_number(1, "atan"); | 67 | double d = luaL_check_number(1, "atan"); |
68 | lua_pushnumber (TODEGREE(atan(d))); | 68 | lua_pushnumber (TODEGREE(atan(d))); |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
72 | static void math_atan2 (void) | 72 | static void math_atan2 (void) |
73 | { | 73 | { |
74 | double d1 = lua_check_number(1, "atan2"); | 74 | double d1 = luaL_check_number(1, "atan2"); |
75 | double d2 = lua_check_number(2, "atan2"); | 75 | double d2 = luaL_check_number(2, "atan2"); |
76 | lua_pushnumber (TODEGREE(atan2(d1, d2))); | 76 | lua_pushnumber (TODEGREE(atan2(d1, d2))); |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | static void math_ceil (void) | 80 | static void math_ceil (void) |
81 | { | 81 | { |
82 | double d = lua_check_number(1, "ceil"); | 82 | double d = luaL_check_number(1, "ceil"); |
83 | lua_pushnumber (ceil(d)); | 83 | lua_pushnumber (ceil(d)); |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | static void math_floor (void) | 87 | static void math_floor (void) |
88 | { | 88 | { |
89 | double d = lua_check_number(1, "floor"); | 89 | double d = luaL_check_number(1, "floor"); |
90 | lua_pushnumber (floor(d)); | 90 | lua_pushnumber (floor(d)); |
91 | } | 91 | } |
92 | 92 | ||
93 | static void math_mod (void) | 93 | static void math_mod (void) |
94 | { | 94 | { |
95 | float x = lua_check_number(1, "mod"); | 95 | float x = luaL_check_number(1, "mod"); |
96 | float y = lua_check_number(2, "mod"); | 96 | float y = luaL_check_number(2, "mod"); |
97 | lua_pushnumber(fmod(x, y)); | 97 | lua_pushnumber(fmod(x, y)); |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | static void math_sqrt (void) | 101 | static void math_sqrt (void) |
102 | { | 102 | { |
103 | double d = lua_check_number(1, "sqrt"); | 103 | double d = luaL_check_number(1, "sqrt"); |
104 | lua_pushnumber (sqrt(d)); | 104 | lua_pushnumber (sqrt(d)); |
105 | } | 105 | } |
106 | 106 | ||
@@ -131,10 +131,10 @@ static void math_pow (void) | |||
131 | static void math_min (void) | 131 | static void math_min (void) |
132 | { | 132 | { |
133 | int i=1; | 133 | int i=1; |
134 | double dmin = lua_check_number(i, "min"); | 134 | double dmin = luaL_check_number(i, "min"); |
135 | while (lua_getparam(++i) != LUA_NOOBJECT) | 135 | while (lua_getparam(++i) != LUA_NOOBJECT) |
136 | { | 136 | { |
137 | double d = lua_check_number(i, "min"); | 137 | double d = luaL_check_number(i, "min"); |
138 | if (d < dmin) dmin = d; | 138 | if (d < dmin) dmin = d; |
139 | } | 139 | } |
140 | lua_pushnumber (dmin); | 140 | lua_pushnumber (dmin); |
@@ -143,10 +143,10 @@ static void math_min (void) | |||
143 | static void math_max (void) | 143 | static void math_max (void) |
144 | { | 144 | { |
145 | int i=1; | 145 | int i=1; |
146 | double dmax = lua_check_number(i, "max"); | 146 | double dmax = luaL_check_number(i, "max"); |
147 | while (lua_getparam(++i) != LUA_NOOBJECT) | 147 | while (lua_getparam(++i) != LUA_NOOBJECT) |
148 | { | 148 | { |
149 | double d = lua_check_number(i, "max"); | 149 | double d = luaL_check_number(i, "max"); |
150 | if (d > dmax) dmax = d; | 150 | if (d > dmax) dmax = d; |
151 | } | 151 | } |
152 | lua_pushnumber (dmax); | 152 | lua_pushnumber (dmax); |
@@ -154,33 +154,33 @@ static void math_max (void) | |||
154 | 154 | ||
155 | static void math_log (void) | 155 | static void math_log (void) |
156 | { | 156 | { |
157 | double d = lua_check_number(1, "log"); | 157 | double d = luaL_check_number(1, "log"); |
158 | lua_pushnumber (log(d)); | 158 | lua_pushnumber (log(d)); |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | static void math_log10 (void) | 162 | static void math_log10 (void) |
163 | { | 163 | { |
164 | double d = lua_check_number(1, "log10"); | 164 | double d = luaL_check_number(1, "log10"); |
165 | lua_pushnumber (log10(d)); | 165 | lua_pushnumber (log10(d)); |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | static void math_exp (void) | 169 | static void math_exp (void) |
170 | { | 170 | { |
171 | double d = lua_check_number(1, "exp"); | 171 | double d = luaL_check_number(1, "exp"); |
172 | lua_pushnumber (exp(d)); | 172 | lua_pushnumber (exp(d)); |
173 | } | 173 | } |
174 | 174 | ||
175 | static void math_deg (void) | 175 | static void math_deg (void) |
176 | { | 176 | { |
177 | float d = lua_check_number(1, "deg"); | 177 | float d = luaL_check_number(1, "deg"); |
178 | lua_pushnumber (d*180./PI); | 178 | lua_pushnumber (d*180./PI); |
179 | } | 179 | } |
180 | 180 | ||
181 | static void math_rad (void) | 181 | static void math_rad (void) |
182 | { | 182 | { |
183 | float d = lua_check_number(1, "rad"); | 183 | float d = luaL_check_number(1, "rad"); |
184 | lua_pushnumber (d/180.*PI); | 184 | lua_pushnumber (d/180.*PI); |
185 | } | 185 | } |
186 | 186 | ||
@@ -191,7 +191,7 @@ static void math_random (void) | |||
191 | 191 | ||
192 | static void math_randomseed (void) | 192 | static void math_randomseed (void) |
193 | { | 193 | { |
194 | srand(lua_check_number(1, "randomseed")); | 194 | srand(luaL_check_number(1, "randomseed")); |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||