diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-14 13:59:27 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-14 13:59:27 -0300 |
| commit | 8b66040e34bb0890bd2627247579a5cf182108d1 (patch) | |
| tree | bb348142cf5297e54bfaf915c1889ee237ac0c2a | |
| parent | 965993da071ff38f14ec49f42ef989d66d717c64 (diff) | |
| download | lua-8b66040e34bb0890bd2627247579a5cf182108d1.tar.gz lua-8b66040e34bb0890bd2627247579a5cf182108d1.tar.bz2 lua-8b66040e34bb0890bd2627247579a5cf182108d1.zip | |
several functions deprecated (cosh, sinh, atanh, pow, frexp, ldexp)
| -rw-r--r-- | lmathlib.c | 138 |
1 files changed, 72 insertions, 66 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.98 2014/04/17 16:09:40 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.99 2014/05/02 16:36:51 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 | */ |
| @@ -48,31 +48,16 @@ static int math_sin (lua_State *L) { | |||
| 48 | return 1; | 48 | return 1; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | static int math_sinh (lua_State *L) { | ||
| 52 | lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1))); | ||
| 53 | return 1; | ||
| 54 | } | ||
| 55 | |||
| 56 | static int math_cos (lua_State *L) { | 51 | static int math_cos (lua_State *L) { |
| 57 | lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1))); | 52 | lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1))); |
| 58 | return 1; | 53 | return 1; |
| 59 | } | 54 | } |
| 60 | 55 | ||
| 61 | static int math_cosh (lua_State *L) { | ||
| 62 | lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1))); | ||
| 63 | return 1; | ||
| 64 | } | ||
| 65 | |||
| 66 | static int math_tan (lua_State *L) { | 56 | static int math_tan (lua_State *L) { |
| 67 | lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1))); | 57 | lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1))); |
| 68 | return 1; | 58 | return 1; |
| 69 | } | 59 | } |
| 70 | 60 | ||
| 71 | static int math_tanh (lua_State *L) { | ||
| 72 | lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1))); | ||
| 73 | return 1; | ||
| 74 | } | ||
| 75 | |||
| 76 | static int math_asin (lua_State *L) { | 61 | static int math_asin (lua_State *L) { |
| 77 | lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1))); | 62 | lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1))); |
| 78 | return 1; | 63 | return 1; |
| @@ -84,13 +69,9 @@ static int math_acos (lua_State *L) { | |||
| 84 | } | 69 | } |
| 85 | 70 | ||
| 86 | static int math_atan (lua_State *L) { | 71 | static int math_atan (lua_State *L) { |
| 87 | lua_pushnumber(L, l_mathop(atan)(luaL_checknumber(L, 1))); | 72 | lua_Number y = luaL_checknumber(L, 1); |
| 88 | return 1; | 73 | lua_Number x = luaL_optnumber(L, 2, 1); |
| 89 | } | 74 | lua_pushnumber(L, l_mathop(atan2)(y, x)); |
| 90 | |||
| 91 | static int math_atan2 (lua_State *L) { | ||
| 92 | lua_pushnumber(L, l_mathop(atan2)(luaL_checknumber(L, 1), | ||
| 93 | luaL_checknumber(L, 2))); | ||
| 94 | return 1; | 75 | return 1; |
| 95 | } | 76 | } |
| 96 | 77 | ||
| @@ -153,13 +134,6 @@ static int math_sqrt (lua_State *L) { | |||
| 153 | return 1; | 134 | return 1; |
| 154 | } | 135 | } |
| 155 | 136 | ||
| 156 | static int math_pow (lua_State *L) { | ||
| 157 | lua_Number x = luaL_checknumber(L, 1); | ||
| 158 | lua_Number y = luaL_checknumber(L, 2); | ||
| 159 | lua_pushnumber(L, l_mathop(pow)(x, y)); | ||
| 160 | return 1; | ||
| 161 | } | ||
| 162 | |||
| 163 | static int math_log (lua_State *L) { | 137 | static int math_log (lua_State *L) { |
| 164 | lua_Number x = luaL_checknumber(L, 1); | 138 | lua_Number x = luaL_checknumber(L, 1); |
| 165 | lua_Number res; | 139 | lua_Number res; |
| @@ -174,13 +148,6 @@ static int math_log (lua_State *L) { | |||
| 174 | return 1; | 148 | return 1; |
| 175 | } | 149 | } |
| 176 | 150 | ||
| 177 | #if defined(LUA_COMPAT_LOG10) | ||
| 178 | static int math_log10 (lua_State *L) { | ||
| 179 | lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1))); | ||
| 180 | return 1; | ||
| 181 | } | ||
| 182 | #endif | ||
| 183 | |||
| 184 | static int math_exp (lua_State *L) { | 151 | static int math_exp (lua_State *L) { |
| 185 | lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1))); | 152 | lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1))); |
| 186 | return 1; | 153 | return 1; |
| @@ -196,38 +163,24 @@ static int math_rad (lua_State *L) { | |||
| 196 | return 1; | 163 | return 1; |
| 197 | } | 164 | } |
| 198 | 165 | ||
| 199 | static int math_frexp (lua_State *L) { | ||
| 200 | int e; | ||
| 201 | lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e)); | ||
| 202 | lua_pushinteger(L, e); | ||
| 203 | return 2; | ||
| 204 | } | ||
| 205 | |||
| 206 | static int math_ldexp (lua_State *L) { | ||
| 207 | lua_Number x = luaL_checknumber(L, 1); | ||
| 208 | int ep = luaL_checkint(L, 2); | ||
| 209 | lua_pushnumber(L, l_mathop(ldexp)(x, ep)); | ||
| 210 | return 1; | ||
| 211 | } | ||
| 212 | |||
| 213 | 166 | ||
| 214 | static int math_min (lua_State *L) { | 167 | static int math_min (lua_State *L) { |
| 215 | int n = lua_gettop(L); /* number of arguments */ | 168 | int n = lua_gettop(L); /* number of arguments */ |
| 216 | int imax = 1; | 169 | int imin = 1; /* index of current minimum value */ |
| 217 | int i; | 170 | int i; |
| 218 | luaL_argcheck(L, n >= 1, 1, "value expected"); | 171 | luaL_argcheck(L, n >= 1, 1, "value expected"); |
| 219 | for (i = 2; i <= n; i++) { | 172 | for (i = 2; i <= n; i++) { |
| 220 | if (lua_compare(L, i, imax, LUA_OPLT)) | 173 | if (lua_compare(L, i, imin, LUA_OPLT)) |
| 221 | imax = i; | 174 | imin = i; |
| 222 | } | 175 | } |
| 223 | lua_pushvalue(L, imax); | 176 | lua_pushvalue(L, imin); |
| 224 | return 1; | 177 | return 1; |
| 225 | } | 178 | } |
| 226 | 179 | ||
| 227 | 180 | ||
| 228 | static int math_max (lua_State *L) { | 181 | static int math_max (lua_State *L) { |
| 229 | int n = lua_gettop(L); /* number of arguments */ | 182 | int n = lua_gettop(L); /* number of arguments */ |
| 230 | int imax = 1; | 183 | int imax = 1; /* index of current maximum value */ |
| 231 | int i; | 184 | int i; |
| 232 | luaL_argcheck(L, n >= 1, 1, "value expected"); | 185 | luaL_argcheck(L, n >= 1, 1, "value expected"); |
| 233 | for (i = 2; i <= n; i++) { | 186 | for (i = 2; i <= n; i++) { |
| @@ -294,39 +247,92 @@ static int math_type (lua_State *L) { | |||
| 294 | } | 247 | } |
| 295 | 248 | ||
| 296 | 249 | ||
| 250 | /* | ||
| 251 | ** {================================================================== | ||
| 252 | ** Deprecated functions (for compatibility only) | ||
| 253 | ** =================================================================== | ||
| 254 | */ | ||
| 255 | #if defined(LUA_COMPAT_MATHLIB) | ||
| 256 | |||
| 257 | static int math_cosh (lua_State *L) { | ||
| 258 | lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1))); | ||
| 259 | return 1; | ||
| 260 | } | ||
| 261 | |||
| 262 | static int math_sinh (lua_State *L) { | ||
| 263 | lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1))); | ||
| 264 | return 1; | ||
| 265 | } | ||
| 266 | |||
| 267 | static int math_tanh (lua_State *L) { | ||
| 268 | lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1))); | ||
| 269 | return 1; | ||
| 270 | } | ||
| 271 | |||
| 272 | static int math_pow (lua_State *L) { | ||
| 273 | lua_Number x = luaL_checknumber(L, 1); | ||
| 274 | lua_Number y = luaL_checknumber(L, 2); | ||
| 275 | lua_pushnumber(L, l_mathop(pow)(x, y)); | ||
| 276 | return 1; | ||
| 277 | } | ||
| 278 | |||
| 279 | static int math_frexp (lua_State *L) { | ||
| 280 | int e; | ||
| 281 | lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e)); | ||
| 282 | lua_pushinteger(L, e); | ||
| 283 | return 2; | ||
| 284 | } | ||
| 285 | |||
| 286 | static int math_ldexp (lua_State *L) { | ||
| 287 | lua_Number x = luaL_checknumber(L, 1); | ||
| 288 | int ep = luaL_checkint(L, 2); | ||
| 289 | lua_pushnumber(L, l_mathop(ldexp)(x, ep)); | ||
| 290 | return 1; | ||
| 291 | } | ||
| 292 | |||
| 293 | static int math_log10 (lua_State *L) { | ||
| 294 | lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1))); | ||
| 295 | return 1; | ||
| 296 | } | ||
| 297 | |||
| 298 | #endif | ||
| 299 | /* }================================================================== */ | ||
| 300 | |||
| 301 | |||
| 302 | |||
| 297 | static const luaL_Reg mathlib[] = { | 303 | static const luaL_Reg mathlib[] = { |
| 298 | {"abs", math_abs}, | 304 | {"abs", math_abs}, |
| 299 | {"acos", math_acos}, | 305 | {"acos", math_acos}, |
| 300 | {"asin", math_asin}, | 306 | {"asin", math_asin}, |
| 301 | {"atan2", math_atan2}, | ||
| 302 | {"atan", math_atan}, | 307 | {"atan", math_atan}, |
| 303 | {"ceil", math_ceil}, | 308 | {"ceil", math_ceil}, |
| 304 | {"cosh", math_cosh}, | ||
| 305 | {"cos", math_cos}, | 309 | {"cos", math_cos}, |
| 306 | {"deg", math_deg}, | 310 | {"deg", math_deg}, |
| 307 | {"exp", math_exp}, | 311 | {"exp", math_exp}, |
| 308 | {"floor", math_floor}, | 312 | {"floor", math_floor}, |
| 309 | {"ifloor", math_ifloor}, | 313 | {"ifloor", math_ifloor}, |
| 310 | {"fmod", math_fmod}, | 314 | {"fmod", math_fmod}, |
| 311 | {"frexp", math_frexp}, | ||
| 312 | {"ldexp", math_ldexp}, | ||
| 313 | #if defined(LUA_COMPAT_LOG10) | ||
| 314 | {"log10", math_log10}, | ||
| 315 | #endif | ||
| 316 | {"log", math_log}, | 315 | {"log", math_log}, |
| 317 | {"max", math_max}, | 316 | {"max", math_max}, |
| 318 | {"min", math_min}, | 317 | {"min", math_min}, |
| 319 | {"modf", math_modf}, | 318 | {"modf", math_modf}, |
| 320 | {"pow", math_pow}, | ||
| 321 | {"rad", math_rad}, | 319 | {"rad", math_rad}, |
| 322 | {"random", math_random}, | 320 | {"random", math_random}, |
| 323 | {"randomseed", math_randomseed}, | 321 | {"randomseed", math_randomseed}, |
| 324 | {"sinh", math_sinh}, | ||
| 325 | {"sin", math_sin}, | 322 | {"sin", math_sin}, |
| 326 | {"sqrt", math_sqrt}, | 323 | {"sqrt", math_sqrt}, |
| 327 | {"tanh", math_tanh}, | ||
| 328 | {"tan", math_tan}, | 324 | {"tan", math_tan}, |
| 329 | {"type", math_type}, | 325 | {"type", math_type}, |
| 326 | #if defined(LUA_COMPAT_MATHLIB) | ||
| 327 | {"atan2", math_atan}, | ||
| 328 | {"cosh", math_cosh}, | ||
| 329 | {"sinh", math_sinh}, | ||
| 330 | {"tanh", math_tanh}, | ||
| 331 | {"pow", math_pow}, | ||
| 332 | {"frexp", math_frexp}, | ||
| 333 | {"ldexp", math_ldexp}, | ||
| 334 | {"log10", math_log10}, | ||
| 335 | #endif | ||
| 330 | {NULL, NULL} | 336 | {NULL, NULL} |
| 331 | }; | 337 | }; |
| 332 | 338 | ||
