【发布时间】:2020-10-21 13:40:44
【问题描述】:
目前我正在学习 C 类型。我有一段 C 代码。这不是整个代码,但我认为其余的与分享无关。 sin 和 cos 函数在上面的原始代码中定义。
C:
double tan(f) double f;
{
return sin(f)/cos(f);
Python:
import ctypes
testlib = ctypes.CDLL('./testlib.so')
testlib.tan.argtypes = ctypes.c_double
teslib.tan.restype = ctypes.c_double
print(testlib.tan(2))
首先我没有使用这些行:
testlib.tan.argtypes = ctypes.c_double
teslib.tan.restype = ctypes.c_double
我得到了一个输出,但输出为 0。我认为 double 值被向下转换为 int。
我想要实现的是我从 python 向 C 发送一个 double,C 会返回一个 double。
我已经熟悉这个文档,但我没有找到正确的答案: https://docs.python.org/3/library/ctypes.html
问题:我应该如何修改我的代码以获得良好的输出?
三
【问题讨论】: