python - 我正在尝试在 python ctypes 中将 float 转换为 str 但它永远不会发生
问题描述
我正在做一个简单的计算器,我需要做一些平方根函数,当我开始时它就出错了。这些是我的代码。
测试.dll
#include <stdio.h>
float negative_check(float num)
{
if(num < 0){
num = -num;
}
return num;
}
float calc_sqrt(int calcFirst)
{
const float difference = 0.00001;
float calcResult = 1.0;
while(negative_check(calcResult * calcResult - calcFirst) >= difference){
calcResult = (calcFirst/calcResult + calcResult)/2.0;
}
return calcResult;
}
Python
from ctypes import *
simple_calc = CDLL("test.dll")
result_var = simple_calc.calc_sqrt(4)
print("Result: ", result_var)
重击
Output: 4502151
但它给了我一些内存地址。我应该怎么办?
解决方案
推荐阅读
- docker - GCP MIG 容器日志到 GCS 存储桶
- gitlab - 如何在浏览器上首次登录 gitLab
- ubuntu - 错误:nginx:[emerg] /etc/nginx/sites-enabled/wordpress.conf 中“return”指令中的参数数量无效
- javascript - nginx javascript模块持久化
- react-native - 当 onChangeText 已经在使用时,有没有办法用 textinput 设置状态?
- powerbi - 我可以在 pbix 中使用雪花模式吗?
- angular - 尝试以角度发布数据时出现未知错误
- javascript - Mongoose 自动改变值的类型
- python - python defaultdict如何使用它而不是函数
- java - Swing/AWT/JavaFX GUI 冻结/NullPointerException