diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-16 13:53:57 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-16 13:53:57 -0200 |
commit | fad57bfa008523c3568b613989a6a3f87f3cb83b (patch) | |
tree | ca47286ada599e45f4445e16d6a410833d4735e8 /mathlib.c | |
parent | 891cab8a31ec73dddb5aa896abedbac53b4c16f8 (diff) | |
download | lua-fad57bfa008523c3568b613989a6a3f87f3cb83b.tar.gz lua-fad57bfa008523c3568b613989a6a3f87f3cb83b.tar.bz2 lua-fad57bfa008523c3568b613989a6a3f87f3cb83b.zip |
new constant LUA_NOOBJECT.
'lua_error' never returns
Diffstat (limited to 'mathlib.c')
-rw-r--r-- | mathlib.c | 114 |
1 files changed, 57 insertions, 57 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.5 1994/11/17 19:43:34 roberto Exp roberto $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.6 1994/11/18 19:46:21 roberto Stab roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> /* NULL */ | 8 | #include <stdio.h> /* NULL */ |
9 | #include <math.h> | 9 | #include <math.h> |
@@ -19,10 +19,10 @@ static void math_abs (void) | |||
19 | { | 19 | { |
20 | double d; | 20 | double d; |
21 | lua_Object o = lua_getparam (1); | 21 | lua_Object o = lua_getparam (1); |
22 | if (o == NULL) | 22 | if (o == LUA_NOOBJECT) |
23 | { lua_error ("too few arguments to function `abs'"); return; } | 23 | lua_error ("too few arguments to function `abs'"); |
24 | if (!lua_isnumber(o)) | 24 | if (!lua_isnumber(o)) |
25 | { lua_error ("incorrect arguments to function `abs'"); return; } | 25 | lua_error ("incorrect arguments to function `abs'"); |
26 | d = lua_getnumber(o); | 26 | d = lua_getnumber(o); |
27 | if (d < 0) d = -d; | 27 | if (d < 0) d = -d; |
28 | lua_pushnumber (d); | 28 | lua_pushnumber (d); |
@@ -33,10 +33,10 @@ static void math_sin (void) | |||
33 | { | 33 | { |
34 | double d; | 34 | double d; |
35 | lua_Object o = lua_getparam (1); | 35 | lua_Object o = lua_getparam (1); |
36 | if (o == NULL) | 36 | if (o == LUA_NOOBJECT) |
37 | { lua_error ("too few arguments to function `sin'"); return; } | 37 | lua_error ("too few arguments to function `sin'"); |
38 | if (!lua_isnumber(o)) | 38 | if (!lua_isnumber(o)) |
39 | { lua_error ("incorrect arguments to function `sin'"); return; } | 39 | lua_error ("incorrect arguments to function `sin'"); |
40 | d = lua_getnumber(o); | 40 | d = lua_getnumber(o); |
41 | lua_pushnumber (sin(TORAD(d))); | 41 | lua_pushnumber (sin(TORAD(d))); |
42 | } | 42 | } |
@@ -47,10 +47,10 @@ static void math_cos (void) | |||
47 | { | 47 | { |
48 | double d; | 48 | double d; |
49 | lua_Object o = lua_getparam (1); | 49 | lua_Object o = lua_getparam (1); |
50 | if (o == NULL) | 50 | if (o == LUA_NOOBJECT) |
51 | { lua_error ("too few arguments to function `cos'"); return; } | 51 | lua_error ("too few arguments to function `cos'"); |
52 | if (!lua_isnumber(o)) | 52 | if (!lua_isnumber(o)) |
53 | { lua_error ("incorrect arguments to function `cos'"); return; } | 53 | lua_error ("incorrect arguments to function `cos'"); |
54 | d = lua_getnumber(o); | 54 | d = lua_getnumber(o); |
55 | lua_pushnumber (cos(TORAD(d))); | 55 | lua_pushnumber (cos(TORAD(d))); |
56 | } | 56 | } |
@@ -61,10 +61,10 @@ static void math_tan (void) | |||
61 | { | 61 | { |
62 | double d; | 62 | double d; |
63 | lua_Object o = lua_getparam (1); | 63 | lua_Object o = lua_getparam (1); |
64 | if (o == NULL) | 64 | if (o == LUA_NOOBJECT) |
65 | { lua_error ("too few arguments to function `tan'"); return; } | 65 | lua_error ("too few arguments to function `tan'"); |
66 | if (!lua_isnumber(o)) | 66 | if (!lua_isnumber(o)) |
67 | { lua_error ("incorrect arguments to function `tan'"); return; } | 67 | lua_error ("incorrect arguments to function `tan'"); |
68 | d = lua_getnumber(o); | 68 | d = lua_getnumber(o); |
69 | lua_pushnumber (tan(TORAD(d))); | 69 | lua_pushnumber (tan(TORAD(d))); |
70 | } | 70 | } |
@@ -74,10 +74,10 @@ static void math_asin (void) | |||
74 | { | 74 | { |
75 | double d; | 75 | double d; |
76 | lua_Object o = lua_getparam (1); | 76 | lua_Object o = lua_getparam (1); |
77 | if (o == NULL) | 77 | if (o == LUA_NOOBJECT) |
78 | { lua_error ("too few arguments to function `asin'"); return; } | 78 | lua_error ("too few arguments to function `asin'"); |
79 | if (!lua_isnumber(o)) | 79 | if (!lua_isnumber(o)) |
80 | { lua_error ("incorrect arguments to function `asin'"); return; } | 80 | lua_error ("incorrect arguments to function `asin'"); |
81 | d = lua_getnumber(o); | 81 | d = lua_getnumber(o); |
82 | lua_pushnumber (TODEGREE(asin(d))); | 82 | lua_pushnumber (TODEGREE(asin(d))); |
83 | } | 83 | } |
@@ -87,10 +87,10 @@ static void math_acos (void) | |||
87 | { | 87 | { |
88 | double d; | 88 | double d; |
89 | lua_Object o = lua_getparam (1); | 89 | lua_Object o = lua_getparam (1); |
90 | if (o == NULL) | 90 | if (o == LUA_NOOBJECT) |
91 | { lua_error ("too few arguments to function `acos'"); return; } | 91 | lua_error ("too few arguments to function `acos'"); |
92 | if (!lua_isnumber(o)) | 92 | if (!lua_isnumber(o)) |
93 | { lua_error ("incorrect arguments to function `acos'"); return; } | 93 | lua_error ("incorrect arguments to function `acos'"); |
94 | d = lua_getnumber(o); | 94 | d = lua_getnumber(o); |
95 | lua_pushnumber (TODEGREE(acos(d))); | 95 | lua_pushnumber (TODEGREE(acos(d))); |
96 | } | 96 | } |
@@ -101,10 +101,10 @@ static void math_atan (void) | |||
101 | { | 101 | { |
102 | double d; | 102 | double d; |
103 | lua_Object o = lua_getparam (1); | 103 | lua_Object o = lua_getparam (1); |
104 | if (o == NULL) | 104 | if (o == LUA_NOOBJECT) |
105 | { lua_error ("too few arguments to function `atan'"); return; } | 105 | lua_error ("too few arguments to function `atan'"); |
106 | if (!lua_isnumber(o)) | 106 | if (!lua_isnumber(o)) |
107 | { lua_error ("incorrect arguments to function `atan'"); return; } | 107 | lua_error ("incorrect arguments to function `atan'"); |
108 | d = lua_getnumber(o); | 108 | d = lua_getnumber(o); |
109 | lua_pushnumber (TODEGREE(atan(d))); | 109 | lua_pushnumber (TODEGREE(atan(d))); |
110 | } | 110 | } |
@@ -114,10 +114,10 @@ static void math_ceil (void) | |||
114 | { | 114 | { |
115 | double d; | 115 | double d; |
116 | lua_Object o = lua_getparam (1); | 116 | lua_Object o = lua_getparam (1); |
117 | if (o == NULL) | 117 | if (o == LUA_NOOBJECT) |
118 | { lua_error ("too few arguments to function `ceil'"); return; } | 118 | lua_error ("too few arguments to function `ceil'"); |
119 | if (!lua_isnumber(o)) | 119 | if (!lua_isnumber(o)) |
120 | { lua_error ("incorrect arguments to function `ceil'"); return; } | 120 | lua_error ("incorrect arguments to function `ceil'"); |
121 | d = lua_getnumber(o); | 121 | d = lua_getnumber(o); |
122 | lua_pushnumber (ceil(d)); | 122 | lua_pushnumber (ceil(d)); |
123 | } | 123 | } |
@@ -127,10 +127,10 @@ static void math_floor (void) | |||
127 | { | 127 | { |
128 | double d; | 128 | double d; |
129 | lua_Object o = lua_getparam (1); | 129 | lua_Object o = lua_getparam (1); |
130 | if (o == NULL) | 130 | if (o == LUA_NOOBJECT) |
131 | { lua_error ("too few arguments to function `floor'"); return; } | 131 | lua_error ("too few arguments to function `floor'"); |
132 | if (!lua_isnumber(o)) | 132 | if (!lua_isnumber(o)) |
133 | { lua_error ("incorrect arguments to function `floor'"); return; } | 133 | lua_error ("incorrect arguments to function `floor'"); |
134 | d = lua_getnumber(o); | 134 | d = lua_getnumber(o); |
135 | lua_pushnumber (floor(d)); | 135 | lua_pushnumber (floor(d)); |
136 | } | 136 | } |
@@ -141,7 +141,7 @@ static void math_mod (void) | |||
141 | lua_Object o1 = lua_getparam (1); | 141 | lua_Object o1 = lua_getparam (1); |
142 | lua_Object o2 = lua_getparam (2); | 142 | lua_Object o2 = lua_getparam (2); |
143 | if (!lua_isnumber(o1) || !lua_isnumber(o2)) | 143 | if (!lua_isnumber(o1) || !lua_isnumber(o2)) |
144 | { lua_error ("incorrect arguments to function `mod'"); return; } | 144 | lua_error ("incorrect arguments to function `mod'"); |
145 | d1 = (int) lua_getnumber(o1); | 145 | d1 = (int) lua_getnumber(o1); |
146 | d2 = (int) lua_getnumber(o2); | 146 | d2 = (int) lua_getnumber(o2); |
147 | lua_pushnumber (d1%d2); | 147 | lua_pushnumber (d1%d2); |
@@ -152,10 +152,10 @@ static void math_sqrt (void) | |||
152 | { | 152 | { |
153 | double d; | 153 | double d; |
154 | lua_Object o = lua_getparam (1); | 154 | lua_Object o = lua_getparam (1); |
155 | if (o == NULL) | 155 | if (o == LUA_NOOBJECT) |
156 | { lua_error ("too few arguments to function `sqrt'"); return; } | 156 | lua_error ("too few arguments to function `sqrt'"); |
157 | if (!lua_isnumber(o)) | 157 | if (!lua_isnumber(o)) |
158 | { lua_error ("incorrect arguments to function `sqrt'"); return; } | 158 | lua_error ("incorrect arguments to function `sqrt'"); |
159 | d = lua_getnumber(o); | 159 | d = lua_getnumber(o); |
160 | lua_pushnumber (sqrt(d)); | 160 | lua_pushnumber (sqrt(d)); |
161 | } | 161 | } |
@@ -188,15 +188,15 @@ static void math_min (void) | |||
188 | int i=1; | 188 | int i=1; |
189 | double d, dmin; | 189 | double d, dmin; |
190 | lua_Object o; | 190 | lua_Object o; |
191 | if ((o = lua_getparam(i++)) == NULL) | 191 | if ((o = lua_getparam(i++)) == LUA_NOOBJECT) |
192 | { lua_error ("too few arguments to function `min'"); return; } | 192 | lua_error ("too few arguments to function `min'"); |
193 | if (!lua_isnumber(o)) | 193 | if (!lua_isnumber(o)) |
194 | { lua_error ("incorrect arguments to function `min'"); return; } | 194 | lua_error ("incorrect arguments to function `min'"); |
195 | dmin = lua_getnumber (o); | 195 | dmin = lua_getnumber (o); |
196 | while ((o = lua_getparam(i++)) != NULL) | 196 | while ((o = lua_getparam(i++)) != LUA_NOOBJECT) |
197 | { | 197 | { |
198 | if (!lua_isnumber(o)) | 198 | if (!lua_isnumber(o)) |
199 | { lua_error ("incorrect arguments to function `min'"); return; } | 199 | lua_error ("incorrect arguments to function `min'"); |
200 | d = lua_getnumber (o); | 200 | d = lua_getnumber (o); |
201 | if (d < dmin) dmin = d; | 201 | if (d < dmin) dmin = d; |
202 | } | 202 | } |
@@ -209,15 +209,15 @@ static void math_max (void) | |||
209 | int i=1; | 209 | int i=1; |
210 | double d, dmax; | 210 | double d, dmax; |
211 | lua_Object o; | 211 | lua_Object o; |
212 | if ((o = lua_getparam(i++)) == NULL) | 212 | if ((o = lua_getparam(i++)) == LUA_NOOBJECT) |
213 | { lua_error ("too few arguments to function `max'"); return; } | 213 | lua_error ("too few arguments to function `max'"); |
214 | if (!lua_isnumber(o)) | 214 | if (!lua_isnumber(o)) |
215 | { lua_error ("incorrect arguments to function `max'"); return; } | 215 | lua_error ("incorrect arguments to function `max'"); |
216 | dmax = lua_getnumber (o); | 216 | dmax = lua_getnumber (o); |
217 | while ((o = lua_getparam(i++)) != NULL) | 217 | while ((o = lua_getparam(i++)) != LUA_NOOBJECT) |
218 | { | 218 | { |
219 | if (!lua_isnumber(o)) | 219 | if (!lua_isnumber(o)) |
220 | { lua_error ("incorrect arguments to function `max'"); return; } | 220 | lua_error ("incorrect arguments to function `max'"); |
221 | d = lua_getnumber (o); | 221 | d = lua_getnumber (o); |
222 | if (d > dmax) dmax = d; | 222 | if (d > dmax) dmax = d; |
223 | } | 223 | } |
@@ -229,10 +229,10 @@ static void math_log (void) | |||
229 | { | 229 | { |
230 | double d; | 230 | double d; |
231 | lua_Object o = lua_getparam (1); | 231 | lua_Object o = lua_getparam (1); |
232 | if (o == NULL) | 232 | if (o == LUA_NOOBJECT) |
233 | { lua_error ("too few arguments to function `log'"); return; } | 233 | lua_error ("too few arguments to function `log'"); |
234 | if (!lua_isnumber(o)) | 234 | if (!lua_isnumber(o)) |
235 | { lua_error ("incorrect arguments to function `log'"); return; } | 235 | lua_error ("incorrect arguments to function `log'"); |
236 | d = lua_getnumber(o); | 236 | d = lua_getnumber(o); |
237 | lua_pushnumber (log(d)); | 237 | lua_pushnumber (log(d)); |
238 | } | 238 | } |
@@ -242,10 +242,10 @@ static void math_log10 (void) | |||
242 | { | 242 | { |
243 | double d; | 243 | double d; |
244 | lua_Object o = lua_getparam (1); | 244 | lua_Object o = lua_getparam (1); |
245 | if (o == NULL) | 245 | if (o == LUA_NOOBJECT) |
246 | { lua_error ("too few arguments to function `log10'"); return; } | 246 | lua_error ("too few arguments to function `log10'"); |
247 | if (!lua_isnumber(o)) | 247 | if (!lua_isnumber(o)) |
248 | { lua_error ("incorrect arguments to function `log10'"); return; } | 248 | lua_error ("incorrect arguments to function `log10'"); |
249 | d = lua_getnumber(o); | 249 | d = lua_getnumber(o); |
250 | lua_pushnumber (log10(d)); | 250 | lua_pushnumber (log10(d)); |
251 | } | 251 | } |
@@ -255,10 +255,10 @@ static void math_exp (void) | |||
255 | { | 255 | { |
256 | double d; | 256 | double d; |
257 | lua_Object o = lua_getparam (1); | 257 | lua_Object o = lua_getparam (1); |
258 | if (o == NULL) | 258 | if (o == LUA_NOOBJECT) |
259 | { lua_error ("too few arguments to function `exp'"); return; } | 259 | lua_error ("too few arguments to function `exp'"); |
260 | if (!lua_isnumber(o)) | 260 | if (!lua_isnumber(o)) |
261 | { lua_error ("incorrect arguments to function `exp'"); return; } | 261 | lua_error ("incorrect arguments to function `exp'"); |
262 | d = lua_getnumber(o); | 262 | d = lua_getnumber(o); |
263 | lua_pushnumber (exp(d)); | 263 | lua_pushnumber (exp(d)); |
264 | } | 264 | } |
@@ -267,10 +267,10 @@ static void math_deg (void) | |||
267 | { | 267 | { |
268 | float d; | 268 | float d; |
269 | lua_Object o = lua_getparam (1); | 269 | lua_Object o = lua_getparam (1); |
270 | if (o == NULL) | 270 | if (o == LUA_NOOBJECT) |
271 | { lua_error ("too few arguments to function `deg'"); return; } | 271 | lua_error ("too few arguments to function `deg'"); |
272 | if (!lua_isnumber(o)) | 272 | if (!lua_isnumber(o)) |
273 | { lua_error ("incorrect arguments to function `deg'"); return; } | 273 | lua_error ("incorrect arguments to function `deg'"); |
274 | d = lua_getnumber(o); | 274 | d = lua_getnumber(o); |
275 | lua_pushnumber (d*180./PI); | 275 | lua_pushnumber (d*180./PI); |
276 | } | 276 | } |
@@ -279,10 +279,10 @@ static void math_rad (void) | |||
279 | { | 279 | { |
280 | float d; | 280 | float d; |
281 | lua_Object o = lua_getparam (1); | 281 | lua_Object o = lua_getparam (1); |
282 | if (o == NULL) | 282 | if (o == LUA_NOOBJECT) |
283 | { lua_error ("too few arguments to function `rad'"); return; } | 283 | lua_error ("too few arguments to function `rad'"); |
284 | if (!lua_isnumber(o)) | 284 | if (!lua_isnumber(o)) |
285 | { lua_error ("incorrect arguments to function `rad'"); return; } | 285 | lua_error ("incorrect arguments to function `rad'"); |
286 | d = lua_getnumber(o); | 286 | d = lua_getnumber(o); |
287 | lua_pushnumber (d/180.*PI); | 287 | lua_pushnumber (d/180.*PI); |
288 | } | 288 | } |