Python 3 integer division. How to make math operators consistant with C

前端 未结 5 1318
野趣味
野趣味 2020-12-06 09:54

I need to port quite a few formulas from C to Python and vice versa. What is the best way to make sure that nothing breaks in the process?

I hope my question doesn\'

5条回答
  •  春和景丽
    2020-12-06 10:05

    You will need to know what the formula does, and understand both the C implementation and how to implement it in Python. But unless you are doing integer maths it should be quite similar, and if you are doing integer maths, the question is why. :)

    Integer maths are either done because of some specific purpose, often related to computers, or because it's faster than floats when doing massive computations, like Fractint does for fractals, and in that case Python is usually not the right choice. ;)

提交回复
热议问题