Operation 10 ** (- 9) is correct in python, but incorrect in Cython

A very simple question: in my python 2.7 code, my situation is something like this:

 b=5.0*10**(-9) a=9 print(a) c=a/(1.0*b) 

the code works in python / spyder (64 bits), but the failure in Cython due to dividing the float by 0. The print number is 0. When I define

 b=0.000000005 

the division is beautiful and the printed number too. What mistake?

+6
source share
1 answer

I can reproduce your error using cython 0.22 , and I think this error is related to this thread in cython-users .

It seems that cython gets into the problem when calculating 10**-9 . If you use 10**-9.0 instead, everything will be fine.

Please note that you can get rid of this error and discard a piece of code by replacing 5.0*10**(-9) with 5e-9 .

However, this seems like a bug in cython, not in your code base.

+5
source

Source: https://habr.com/ru/post/987134/


All Articles