3 ms·
Did anyone even read his code? The C code gets the wrong answers once its integers overflow. The Python code will produce the correct answer using longs once
by afhof 14y ago
Did anyone even read his code? The C code gets the wrong answers once its integers overflow. The Python code will produce the correct answer using longs once the integer calculations overflow. Ctypes is the right answer for a different problem.
- jiaaro 14y agoI agree that it'd be more correct to make the C and python code output the same answer. The important thing here is how to hook up C code to python. the benchmarks are still (mostly) valid because it's still the same number of addition operations (regardless of the overflow). Honestly, I'm not a very good C programmer (as you can see). I was really just documenting how to do this for myself. I never expected to get such a big surge of traffic from HN. That being said, I'll take a second look at the code and try to make it more correct, suggestions welcome!
- jiaaro 14y agoI updated the post to use unsigned long long for the values (which does not overflow) I timed the calls again, but didn't bother to update the values in the post as they were within 1% of the original timings