更新时间:2023-02-11 09:47:15
我不确定您能做到这一点(例如,使用十进制类或numpy)而不修改c代码吗?无需修改C代码。 ctypes似乎对 long double
s的支持确实很差-您根本无法像数字一样操纵它们,您所能做的就是在本机 float
Python类型。
I'm not sure you can do it without modifying the C code. ctypes seems to have really bad support for long double
s - you can't manipulate them like numbers at all, all you can do is convert them back and forth between the native float
Python type.
您甚至不能使用字节数组作为返回值,而不能使用 c_longdouble
,由于ABI的缘故,浮点值不会像普通返回一样在%eax
寄存器或堆栈中返回值,它们通过硬件专用的浮点寄存器传递。
You can't even use a byte array as the return value instead of a c_longdouble
, because of the ABI - floating-point values aren't returned in the %eax
register or on the stack like normal return values, they're passed through the hardware-specific floating-point registers.