diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-11-28 18:13:13 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-11-28 18:13:13 -0200 |
| commit | 72659a06050632da1a9b4c492302be46ac283f6b (patch) | |
| tree | bac06b4ea523ba5443564d0869e392180d4b7b77 /lmathlib.c | |
| parent | dfaf8c5291fa8aef5bedbfa375853475364ac76e (diff) | |
| download | lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.gz lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.bz2 lua-72659a06050632da1a9b4c492302be46ac283f6b.zip | |
no more explicit support for wide-chars; too much troble...
Diffstat (limited to 'lmathlib.c')
| -rw-r--r-- | lmathlib.c | 59 |
1 files changed, 29 insertions, 30 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.37 2001/03/06 20:09:38 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.38 2001/03/26 14:31:49 roberto Exp $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <math.h> | 9 | #include <math.h> |
| 10 | 10 | ||
| 11 | #define LUA_PRIVATE | ||
| 12 | #include "lua.h" | 11 | #include "lua.h" |
| 13 | 12 | ||
| 14 | #include "lauxlib.h" | 13 | #include "lauxlib.h" |
| @@ -177,18 +176,18 @@ static int math_random (lua_State *L) { | |||
| 177 | } | 176 | } |
| 178 | case 1: { /* only upper limit */ | 177 | case 1: { /* only upper limit */ |
| 179 | int u = luaL_check_int(L, 1); | 178 | int u = luaL_check_int(L, 1); |
| 180 | luaL_arg_check(L, 1<=u, 1, l_s("interval is empty")); | 179 | luaL_arg_check(L, 1<=u, 1, "interval is empty"); |
| 181 | lua_pushnumber(L, (int)(r*u)+1); /* integer between 1 and `u' */ | 180 | lua_pushnumber(L, (int)(r*u)+1); /* integer between 1 and `u' */ |
| 182 | break; | 181 | break; |
| 183 | } | 182 | } |
| 184 | case 2: { /* lower and upper limits */ | 183 | case 2: { /* lower and upper limits */ |
| 185 | int l = luaL_check_int(L, 1); | 184 | int l = luaL_check_int(L, 1); |
| 186 | int u = luaL_check_int(L, 2); | 185 | int u = luaL_check_int(L, 2); |
| 187 | luaL_arg_check(L, l<=u, 2, l_s("interval is empty")); | 186 | luaL_arg_check(L, l<=u, 2, "interval is empty"); |
| 188 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ | 187 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ |
| 189 | break; | 188 | break; |
| 190 | } | 189 | } |
| 191 | default: lua_error(L, l_s("wrong number of arguments")); | 190 | default: lua_error(L, "wrong number of arguments"); |
| 192 | } | 191 | } |
| 193 | return 1; | 192 | return 1; |
| 194 | } | 193 | } |
| @@ -201,29 +200,29 @@ static int math_randomseed (lua_State *L) { | |||
| 201 | 200 | ||
| 202 | 201 | ||
| 203 | static const luaL_reg mathlib[] = { | 202 | static const luaL_reg mathlib[] = { |
| 204 | {l_s("abs"), math_abs}, | 203 | {"abs", math_abs}, |
| 205 | {l_s("sin"), math_sin}, | 204 | {"sin", math_sin}, |
| 206 | {l_s("cos"), math_cos}, | 205 | {"cos", math_cos}, |
| 207 | {l_s("tan"), math_tan}, | 206 | {"tan", math_tan}, |
| 208 | {l_s("asin"), math_asin}, | 207 | {"asin", math_asin}, |
| 209 | {l_s("acos"), math_acos}, | 208 | {"acos", math_acos}, |
| 210 | {l_s("atan"), math_atan}, | 209 | {"atan", math_atan}, |
| 211 | {l_s("atan2"), math_atan2}, | 210 | {"atan2", math_atan2}, |
| 212 | {l_s("ceil"), math_ceil}, | 211 | {"ceil", math_ceil}, |
| 213 | {l_s("floor"), math_floor}, | 212 | {"floor", math_floor}, |
| 214 | {l_s("mod"), math_mod}, | 213 | {"mod", math_mod}, |
| 215 | {l_s("frexp"), math_frexp}, | 214 | {"frexp", math_frexp}, |
| 216 | {l_s("ldexp"), math_ldexp}, | 215 | {"ldexp", math_ldexp}, |
| 217 | {l_s("sqrt"), math_sqrt}, | 216 | {"sqrt", math_sqrt}, |
| 218 | {l_s("min"), math_min}, | 217 | {"min", math_min}, |
| 219 | {l_s("max"), math_max}, | 218 | {"max", math_max}, |
| 220 | {l_s("log"), math_log}, | 219 | {"log", math_log}, |
| 221 | {l_s("log10"), math_log10}, | 220 | {"log10", math_log10}, |
| 222 | {l_s("exp"), math_exp}, | 221 | {"exp", math_exp}, |
| 223 | {l_s("deg"), math_deg}, | 222 | {"deg", math_deg}, |
| 224 | {l_s("rad"), math_rad}, | 223 | {"rad", math_rad}, |
| 225 | {l_s("random"), math_random}, | 224 | {"random", math_random}, |
| 226 | {l_s("randomseed"), math_randomseed} | 225 | {"randomseed", math_randomseed} |
| 227 | }; | 226 | }; |
| 228 | 227 | ||
| 229 | /* | 228 | /* |
| @@ -232,9 +231,9 @@ static const luaL_reg mathlib[] = { | |||
| 232 | LUALIB_API int lua_mathlibopen (lua_State *L) { | 231 | LUALIB_API int lua_mathlibopen (lua_State *L) { |
| 233 | luaL_openl(L, mathlib); | 232 | luaL_openl(L, mathlib); |
| 234 | lua_pushcfunction(L, math_pow); | 233 | lua_pushcfunction(L, math_pow); |
| 235 | lua_settagmethod(L, LUA_TNUMBER, l_s("pow")); | 234 | lua_settagmethod(L, LUA_TNUMBER, "pow"); |
| 236 | lua_pushnumber(L, PI); | 235 | lua_pushnumber(L, PI); |
| 237 | lua_setglobal(L, l_s("PI")); | 236 | lua_setglobal(L, "PI"); |
| 238 | return 0; | 237 | return 0; |
| 239 | } | 238 | } |
| 240 | 239 | ||
