picrin/src/number.c

101 lines
1.6 KiB
C
Raw Normal View History

2013-10-15 10:26:18 -04:00
#include <math.h>
#include "picrin.h"
2013-10-16 04:43:38 -04:00
static pic_value
pic_number_lt(pic_state *pic)
{
double f,g;
pic_get_args(pic, "ff", &f, &g);
if (f < g) {
return pic_true_value();
}
else {
return pic_false_value();
}
}
2013-10-15 10:26:18 -04:00
static pic_value
pic_number_sqrt(pic_state *pic)
{
double f;
pic_get_args(pic, "f", &f);
f = sqrt(f);
return pic_float_value(f);
}
static pic_value
pic_number_sin(pic_state *pic)
{
double f;
pic_get_args(pic, "f", &f);
f = sin(f);
return pic_float_value(f);
}
static pic_value
pic_number_cos(pic_state *pic)
{
double f;
pic_get_args(pic, "f", &f);
f = cos(f);
return pic_float_value(f);
}
static pic_value
pic_number_tan(pic_state *pic)
{
double f;
pic_get_args(pic, "f", &f);
f = tan(f);
return pic_float_value(f);
}
static pic_value
pic_number_acos(pic_state *pic)
{
double f;
pic_get_args(pic, "f", &f);
f = acos(f);
return pic_float_value(f);
}
static pic_value
pic_number_asin(pic_state *pic)
{
double f;
pic_get_args(pic, "f", &f);
f = asin(f);
return pic_float_value(f);
}
static pic_value
pic_number_atan(pic_state *pic)
{
double f;
pic_get_args(pic, "f", &f);
f = atan(f);
return pic_float_value(f);
}
void
pic_init_number(pic_state *pic)
{
2013-10-16 04:43:38 -04:00
pic_defun(pic, "<", pic_number_lt);
2013-10-15 10:26:18 -04:00
pic_defun(pic, "sqrt", pic_number_sqrt);
pic_defun(pic, "sin", pic_number_sin);
pic_defun(pic, "cos", pic_number_cos);
pic_defun(pic, "tan", pic_number_tan);
pic_defun(pic, "acos", pic_number_acos);
pic_defun(pic, "asin", pic_number_asin);
pic_defun(pic, "atan", pic_number_atan);
}