As I started to write tests for my calculations I noticed the following issue:
>>> np.multiply(0.55, 20)
11.0
>>> np.multiply(np.float(0.55), 20)
11.0
>>> np.multiply(np.float128(0.55), 20)
11.000000000000000888
>>> np.ceil(np.multiply(0.55, 20))
11.0
>>> np.ceil(np.multiply(np.float128(0.55), 20))
12.0
As seen in the example using the np.float128
class results in a different solution of the calculation. I've been using the numpy functions(e.g., np.multiply
) in combination with the np.float128
class because I thought that this would give me more precise calculation results.
So my question is: What is the best way to handle rather complex calculations in python?
I would be fine with loosing high precision if I'm getting correct results.