diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1993-12-17 16:41:19 -0200 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1993-12-17 16:41:19 -0200 |
commit | b74cea9ebf5073d75a345e9205395f6ebae6b793 (patch) | |
tree | 147a6fe23ba8273cc423cc11de9e218011ed7e08 | |
parent | f3f0e3db91dca767b9d7aeafb85bfc6f6ffe8f6f (diff) | |
download | lua-b74cea9ebf5073d75a345e9205395f6ebae6b793.tar.gz lua-b74cea9ebf5073d75a345e9205395f6ebae6b793.tar.bz2 lua-b74cea9ebf5073d75a345e9205395f6ebae6b793.zip |
Mathematics library to LUA
-rw-r--r-- | mathlib.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -1,17 +1,18 @@ | |||
1 | /* | 1 | /* |
2 | ** mathlib.c | 2 | ** mathlib.c |
3 | ** Mathematica library to LUA | 3 | ** Mathematics library to LUA |
4 | ** | ||
5 | ** Waldemar Celes Filho | ||
6 | ** TeCGraf - PUC-Rio | ||
7 | ** 19 May 93 | ||
8 | */ | 4 | */ |
9 | 5 | ||
6 | char *rcs_mathlib="$Id: $"; | ||
7 | |||
10 | #include <stdio.h> /* NULL */ | 8 | #include <stdio.h> /* NULL */ |
11 | #include <math.h> | 9 | #include <math.h> |
12 | 10 | ||
13 | #include "lua.h" | 11 | #include "lua.h" |
14 | 12 | ||
13 | #define TODEGREE(a) ((a)*180.0/3.14159) | ||
14 | #define TORAD(a) ((a)*3.14159/180.0) | ||
15 | |||
15 | static void math_abs (void) | 16 | static void math_abs (void) |
16 | { | 17 | { |
17 | double d; | 18 | double d; |
@@ -35,7 +36,7 @@ static void math_sin (void) | |||
35 | if (!lua_isnumber(o)) | 36 | if (!lua_isnumber(o)) |
36 | { lua_error ("incorrect arguments to function `sin'"); return; } | 37 | { lua_error ("incorrect arguments to function `sin'"); return; } |
37 | d = lua_getnumber(o); | 38 | d = lua_getnumber(o); |
38 | lua_pushnumber (sin(d)); | 39 | lua_pushnumber (sin(TORAD(d))); |
39 | } | 40 | } |
40 | 41 | ||
41 | 42 | ||
@@ -49,7 +50,7 @@ static void math_cos (void) | |||
49 | if (!lua_isnumber(o)) | 50 | if (!lua_isnumber(o)) |
50 | { lua_error ("incorrect arguments to function `cos'"); return; } | 51 | { lua_error ("incorrect arguments to function `cos'"); return; } |
51 | d = lua_getnumber(o); | 52 | d = lua_getnumber(o); |
52 | lua_pushnumber (cos(d)); | 53 | lua_pushnumber (cos(TORAD(d))); |
53 | } | 54 | } |
54 | 55 | ||
55 | 56 | ||
@@ -63,7 +64,7 @@ static void math_tan (void) | |||
63 | if (!lua_isnumber(o)) | 64 | if (!lua_isnumber(o)) |
64 | { lua_error ("incorrect arguments to function `tan'"); return; } | 65 | { lua_error ("incorrect arguments to function `tan'"); return; } |
65 | d = lua_getnumber(o); | 66 | d = lua_getnumber(o); |
66 | lua_pushnumber (tan(d)); | 67 | lua_pushnumber (tan(TORAD(d))); |
67 | } | 68 | } |
68 | 69 | ||
69 | 70 | ||
@@ -76,7 +77,7 @@ static void math_asin (void) | |||
76 | if (!lua_isnumber(o)) | 77 | if (!lua_isnumber(o)) |
77 | { lua_error ("incorrect arguments to function `asin'"); return; } | 78 | { lua_error ("incorrect arguments to function `asin'"); return; } |
78 | d = lua_getnumber(o); | 79 | d = lua_getnumber(o); |
79 | lua_pushnumber (asin(d)); | 80 | lua_pushnumber (TODEGREE(asin(d))); |
80 | } | 81 | } |
81 | 82 | ||
82 | 83 | ||
@@ -89,7 +90,7 @@ static void math_acos (void) | |||
89 | if (!lua_isnumber(o)) | 90 | if (!lua_isnumber(o)) |
90 | { lua_error ("incorrect arguments to function `acos'"); return; } | 91 | { lua_error ("incorrect arguments to function `acos'"); return; } |
91 | d = lua_getnumber(o); | 92 | d = lua_getnumber(o); |
92 | lua_pushnumber (acos(d)); | 93 | lua_pushnumber (TODEGREE(acos(d))); |
93 | } | 94 | } |
94 | 95 | ||
95 | 96 | ||
@@ -103,7 +104,7 @@ static void math_atan (void) | |||
103 | if (!lua_isnumber(o)) | 104 | if (!lua_isnumber(o)) |
104 | { lua_error ("incorrect arguments to function `atan'"); return; } | 105 | { lua_error ("incorrect arguments to function `atan'"); return; } |
105 | d = lua_getnumber(o); | 106 | d = lua_getnumber(o); |
106 | lua_pushnumber (atan(d)); | 107 | lua_pushnumber (TODEGREE(atan(d))); |
107 | } | 108 | } |
108 | 109 | ||
109 | 110 | ||