pikapython/package/PikaMath/PikaMath_Math.c

108 lines
2.1 KiB
C
Raw Normal View History

2022-06-12 10:44:32 +08:00
#include "PikaMath_Math.h"
#include <math.h>
#define PI (3.141592653589793115997963468544185161590576171875l)
#define E (2.718281828459045090795598298427648842334747314453125l)
//初始化填入π和e的值
void PikaMath_Math___init__(PikaObj *self)
{
obj_setFloat(self, "pi", PI);
obj_setFloat(self, "e", PI);
}
double PikaMath_Math_acos(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return acos(x);
}
double PikaMath_Math_asin(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return asin(x);
}
double PikaMath_Math_atan(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return atan(x);
}
double PikaMath_Math_atan2(PikaObj *self, double x, double y)
2022-06-12 10:44:32 +08:00
{
return atan2(x,y);
}
int PikaMath_Math_ceil(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return ceil(x);
}
double PikaMath_Math_cos(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return cos(x);
}
double PikaMath_Math_cosh(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return cosh(x);
}
double PikaMath_Math_degrees(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return x*180.0/PI;
}
double PikaMath_Math_exp(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return exp(x);
}
double PikaMath_Math_fabs(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return fabs(x);
}
int PikaMath_Math_floor(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return floor(x);
}
double PikaMath_Math_fmod(PikaObj *self, double x, double y)
2022-06-12 10:44:32 +08:00
{
return fmod(x,y);
}
double PikaMath_Math_log(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return log(x);
}
double PikaMath_Math_log10(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return log10(x);
}
double PikaMath_Math_log2(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return log2(x);
}
double PikaMath_Math_pow(PikaObj *self, double x, double y)
2022-06-12 10:44:32 +08:00
{
return pow(x,y);
}
double PikaMath_Math_radians(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return x*PI/180.0;
}
double PikaMath_Math_remainder(PikaObj *self, double x, double y)
2022-06-12 10:44:32 +08:00
{
return remainder(x,y);
}
double PikaMath_Math_sin(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return sin(x);
}
double PikaMath_Math_sinh(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return sinh(x);
}
double PikaMath_Math_sqrt(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return sqrt(x);
}
double PikaMath_Math_tan(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return tan(x);
}
double PikaMath_Math_tanh(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return tanh(x);
}
double PikaMath_Math_trunc(PikaObj *self, double x)
2022-06-12 10:44:32 +08:00
{
return trunc(x);
}