I'm making a simple calculator and i need to do some square root function and when i start that it comes wrong. These are my codes.
test.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)
bash
Output: 4502151
But it gaves me some memory adresses. What should i do?