1 Star 0 Fork 86

luise1987/pythonvm

forked from hinus/pythonvm 
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
math.cpp 844 Bytes
Copy Edit Raw Blame History
hinus authored 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/luise1987/pythonvm.git
git@gitee.com:luise1987/pythonvm.git
luise1987
pythonvm
pythonvm
master

Search