1 Star 0 Fork 86

77-0/pythonvm

forked from hinus/pythonvm 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
math.cpp 844 Bytes
一键复制 编辑 原始数据 按行查看 历史
hinus 提交于 2018-10-08 22:43 +08:00 . Summary: double & sin, sqrt
#include "inc/railgun.hpp"
#include <math.h>
double get_double(ObjList args) {
HiObject* x = args->get(0);
double y = 0;
if (x->klass() == IntegerKlass::get_instance()) {
y = ((HiInteger*)x)->value();
}
else if (x->klass() == DoubleKlass::get_instance()) {
y = ((HiDouble*)x)->value();
}
return y;
}
HiObject* math_sqrt(ObjList args) {
double x = get_double(args);
return new HiDouble(sqrt(x));
}
HiObject* math_sin(ObjList args) {
double x = get_double(args);
return new HiDouble(sin(x));
}
RGMethod math_methods[] = {
{ "sin", math_sin, 0, "sin(x)", },
{ "sqrt", math_sqrt, 0, "square root of x", },
{ NULL, NULL, 0, NULL, },
};
#ifdef __cplusplus
extern "C" {
#endif
SO_PUBLIC RGMethod* init_libmath() {
return math_methods;
}
#ifdef __cplusplus
}
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/l77-0/pythonvm.git
git@gitee.com:l77-0/pythonvm.git
l77-0
pythonvm
pythonvm
master

搜索帮助