/* real  - functions for reals */
/*
        G.C.Wraith  28/11/94

*/

#include <math.h>
#include "bob.h"

int xacos(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = sp->v.v_real;
 if (fabs(x)>1)
    error0("Out of range for acos");
 set_real(&sp[1],acos(x));
 ++sp;
 return(0);
}

int xasin(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = sp->v.v_real;
 if (fabs(x)>1)
    error0("Out of range for asin");   
 set_real(&sp[1],asin(x));
 ++sp;
 return(0);
}

int xatan(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = atan(sp->v.v_real);
 set_real(&sp[1],x);
 ++sp;
 return(0);
}

int xcos(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = cos(sp->v.v_real);
 set_real(&sp[1],x);
 ++sp;
 return(0);
}

int xsin(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = sin(sp->v.v_real);
 set_real(&sp[1],x);
 ++sp;
 return(0);
}

int xtan(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = tan(sp->v.v_real);
 set_real(&sp[1],x);
 ++sp;
 return(0);
}

int xexp(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = exp(sp->v.v_real);
 set_real(&sp[1],x);
 ++sp;
 return(0);
}

int xlog(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = sp->v.v_real;
 if (x < 0)
    error0("Negative argument to log");
 set_real(&sp[1],log(x));
 ++sp;
 return(0);
}

int xsqrt(int argc)
{
 double x;
 argcount(argc,1);
 chktype(0,DT_REAL);
 x = sp->v.v_real;
 if (x < 0)
    error0("Negative argument to sqrt");
 set_real(&sp[1],sqrt(x));
 ++sp;
 return(0);
}

int xfloor(int argc)
{
 argcount(argc,1);
 chktype(0,DT_REAL);
 set_integer(&sp[1],floor(sp->v.v_real));
 ++sp;
 return(0);
}

void init_real_functions(void)
{
 add_function("acos",xacos);
 add_function("asin",xasin);
 add_function("atan",xatan);
 add_function("cos",xcos);
 add_function("sin",xsin);
 add_function("tan",xtan);
 add_function("exp",xexp);
 add_function("log",xlog);
 add_function("sqrt",xsqrt);
 add_function("floor",xfloor); 
}
