DEV Community

Discussion on: How to Use C Functions in Python

Collapse
 
stefano1511 profile image
Stefano1511

Hi Erik, thanks for the reply. I did your recommendation but it doesn't work. I was thinking that the problem is with gcc but I am not sure. Do you have any other idea?

Thread Thread
 
erikwhiting88 profile image
Erik

I tried it out too. It's definitely weird. It's "working" for me but it's not giving me the right answer. I never tested that high. I'm at work now and can't really dig into it but if I get some time I'll let you know.

Thread Thread
 
stefano1511 profile image
Stefano1511

Sure, thanks again!

Thread Thread
 
benh42 profile image
Ben Hartley

Not sure if this thread will be active again, but I found that on the c side of the program (using long long) it is accurate up to 20! . I found this by adding a printf statement in cfactorial.c . So it seems that at some point in the process of python and c communicating, the true value is lost.

Thread Thread
 
erikwhiting88 profile image
Erik

interesting. perhaps ints in C are represented differently in memory than in Python. maybe the best way is to parse the int into a char array and send it to Python as a string?

Thread Thread
 
benh42 profile image
Ben Hartley

That does sound promising because I imagine it could scale almost indefinitely if its not bound by the long or long long limits