mic
mic

Reputation: 117

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

Very basic question: in my python 2.7 code I have situation roughly as follows:

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

the code runs in python / spyder (64bit), but fails in Cython, because of a float division by 0. The printed number is 0. When I define

b=0.000000005

the division is fine and the printed number, too. What is the error?

Upvotes: 6

Views: 347

Answers (1)

cel
cel

Reputation: 31369

I can reproduce your error with cython 0.22 and I think this error is related to this thread at cython-users.

It seems that cython gets into trouble when calculating 10**-9. If you use 10**-9.0 instead, everything works fine.

Note, that you could get rid of the error and prettify the code snippet by replacing 5.0*10**(-9) by 5e-9.

Nevertheless this seems to be a bug in cython and not in your code base.

Upvotes: 5

Related Questions