|
@ -1,17 +1,18 @@ |
|
|
/*
|
|
|
/*
|
|
|
** mathlib.c |
|
|
** mathlib.c |
|
|
** Mathematica library to LUA |
|
|
** Mathematics library to LUA |
|
|
** |
|
|
|
|
|
** Waldemar Celes Filho |
|
|
|
|
|
** TeCGraf - PUC-Rio |
|
|
|
|
|
** 19 May 93 |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
char *rcs_mathlib="$Id: $"; |
|
|
|
|
|
|
|
|
#include <stdio.h> /* NULL */ |
|
|
#include <stdio.h> /* NULL */ |
|
|
#include <math.h> |
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
#include "lua.h" |
|
|
#include "lua.h" |
|
|
|
|
|
|
|
|
|
|
|
#define TODEGREE(a) ((a)*180.0/3.14159) |
|
|
|
|
|
#define TORAD(a) ((a)*3.14159/180.0) |
|
|
|
|
|
|
|
|
static void math_abs (void) |
|
|
static void math_abs (void) |
|
|
{ |
|
|
{ |
|
|
double d; |
|
|
double d; |
|
@ -35,7 +36,7 @@ static void math_sin (void) |
|
|
if (!lua_isnumber(o)) |
|
|
if (!lua_isnumber(o)) |
|
|
{ lua_error ("incorrect arguments to function `sin'"); return; } |
|
|
{ lua_error ("incorrect arguments to function `sin'"); return; } |
|
|
d = lua_getnumber(o); |
|
|
d = lua_getnumber(o); |
|
|
lua_pushnumber (sin(d)); |
|
|
lua_pushnumber (sin(TORAD(d))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +50,7 @@ static void math_cos (void) |
|
|
if (!lua_isnumber(o)) |
|
|
if (!lua_isnumber(o)) |
|
|
{ lua_error ("incorrect arguments to function `cos'"); return; } |
|
|
{ lua_error ("incorrect arguments to function `cos'"); return; } |
|
|
d = lua_getnumber(o); |
|
|
d = lua_getnumber(o); |
|
|
lua_pushnumber (cos(d)); |
|
|
lua_pushnumber (cos(TORAD(d))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,7 +64,7 @@ static void math_tan (void) |
|
|
if (!lua_isnumber(o)) |
|
|
if (!lua_isnumber(o)) |
|
|
{ lua_error ("incorrect arguments to function `tan'"); return; } |
|
|
{ lua_error ("incorrect arguments to function `tan'"); return; } |
|
|
d = lua_getnumber(o); |
|
|
d = lua_getnumber(o); |
|
|
lua_pushnumber (tan(d)); |
|
|
lua_pushnumber (tan(TORAD(d))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -76,7 +77,7 @@ static void math_asin (void) |
|
|
if (!lua_isnumber(o)) |
|
|
if (!lua_isnumber(o)) |
|
|
{ lua_error ("incorrect arguments to function `asin'"); return; } |
|
|
{ lua_error ("incorrect arguments to function `asin'"); return; } |
|
|
d = lua_getnumber(o); |
|
|
d = lua_getnumber(o); |
|
|
lua_pushnumber (asin(d)); |
|
|
lua_pushnumber (TODEGREE(asin(d))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -89,7 +90,7 @@ static void math_acos (void) |
|
|
if (!lua_isnumber(o)) |
|
|
if (!lua_isnumber(o)) |
|
|
{ lua_error ("incorrect arguments to function `acos'"); return; } |
|
|
{ lua_error ("incorrect arguments to function `acos'"); return; } |
|
|
d = lua_getnumber(o); |
|
|
d = lua_getnumber(o); |
|
|
lua_pushnumber (acos(d)); |
|
|
lua_pushnumber (TODEGREE(acos(d))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -103,7 +104,7 @@ static void math_atan (void) |
|
|
if (!lua_isnumber(o)) |
|
|
if (!lua_isnumber(o)) |
|
|
{ lua_error ("incorrect arguments to function `atan'"); return; } |
|
|
{ lua_error ("incorrect arguments to function `atan'"); return; } |
|
|
d = lua_getnumber(o); |
|
|
d = lua_getnumber(o); |
|
|
lua_pushnumber (atan(d)); |
|
|
lua_pushnumber (TODEGREE(atan(d))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|