diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-09 14:29:46 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-09 14:29:46 -0300 |
commit | fdd137276b73eec65545f8240e155df2072c8882 (patch) | |
tree | 4725200d2facf0856bf934e51d9ee61e808da085 /lmathlib.c | |
parent | a8aede68c749c554ef5368f31550812f7a9a345a (diff) | |
download | lua-fdd137276b73eec65545f8240e155df2072c8882.tar.gz lua-fdd137276b73eec65545f8240e155df2072c8882.tar.bz2 lua-fdd137276b73eec65545f8240e155df2072c8882.zip |
more precision for PI + no more RADIANS_PER_DEGREE +
'min/maxint' -> 'min/maxinteger'
Diffstat (limited to 'lmathlib.c')
-rw-r--r-- | lmathlib.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.94 2014/04/01 14:39:55 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.95 2014/04/03 14:18:19 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 | */ |
@@ -18,8 +18,7 @@ | |||
18 | 18 | ||
19 | 19 | ||
20 | #undef PI | 20 | #undef PI |
21 | #define PI ((lua_Number)(3.1415926535897932384626433832795)) | 21 | #define PI (l_mathop(3.141592653589793238462643383279502884)) |
22 | #define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0)) | ||
23 | 22 | ||
24 | 23 | ||
25 | static int math_abs (lua_State *L) { | 24 | static int math_abs (lua_State *L) { |
@@ -167,12 +166,12 @@ static int math_exp (lua_State *L) { | |||
167 | } | 166 | } |
168 | 167 | ||
169 | static int math_deg (lua_State *L) { | 168 | static int math_deg (lua_State *L) { |
170 | lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); | 169 | lua_pushnumber(L, luaL_checknumber(L, 1) * (180.0 / PI)); |
171 | return 1; | 170 | return 1; |
172 | } | 171 | } |
173 | 172 | ||
174 | static int math_rad (lua_State *L) { | 173 | static int math_rad (lua_State *L) { |
175 | lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); | 174 | lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / 180.0)); |
176 | return 1; | 175 | return 1; |
177 | } | 176 | } |
178 | 177 | ||
@@ -317,9 +316,9 @@ LUAMOD_API int luaopen_math (lua_State *L) { | |||
317 | lua_pushnumber(L, HUGE_VAL); | 316 | lua_pushnumber(L, HUGE_VAL); |
318 | lua_setfield(L, -2, "huge"); | 317 | lua_setfield(L, -2, "huge"); |
319 | lua_pushinteger(L, LUA_MAXINTEGER); | 318 | lua_pushinteger(L, LUA_MAXINTEGER); |
320 | lua_setfield(L, -2, "maxint"); | 319 | lua_setfield(L, -2, "maxinteger"); |
321 | lua_pushinteger(L, LUA_MININTEGER); | 320 | lua_pushinteger(L, LUA_MININTEGER); |
322 | lua_setfield(L, -2, "minint"); | 321 | lua_setfield(L, -2, "mininteger"); |
323 | return 1; | 322 | return 1; |
324 | } | 323 | } |
325 | 324 | ||