aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-09 14:29:46 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-09 14:29:46 -0300
commitfdd137276b73eec65545f8240e155df2072c8882 (patch)
tree4725200d2facf0856bf934e51d9ee61e808da085 /lmathlib.c
parenta8aede68c749c554ef5368f31550812f7a9a345a (diff)
downloadlua-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.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/lmathlib.c b/lmathlib.c
index 5e7b1d64..d93f2d65 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -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
25static int math_abs (lua_State *L) { 24static int math_abs (lua_State *L) {
@@ -167,12 +166,12 @@ static int math_exp (lua_State *L) {
167} 166}
168 167
169static int math_deg (lua_State *L) { 168static 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
174static int math_rad (lua_State *L) { 173static 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