Search code examples
cythondivide-by-zero

Cython Float Division Error: Zero Division (Numbers too big or too small?)


I have a really odd zero division error. I have the code

from numpy import pi
cdef double a0 = 0.02
cdef double c = 2.998e8
cdef double me = 9e-31
cdef double s = 50.0
cdef L = 800e-9
cdef q = 1.602e-19  
cdef double E1=(a0*c*me*s*L*sqrt(pi))/(q*(1.602*10**(-13))*sqrt(2.0)) #some code

Yet it gives a

ZeroDivisionError: float division

despite the fact that they are all doubles. Are these numbers too big or two small for the double data type? I tested this calculation in the python shell and there is no error. Thanks in advance for the help and/or suggestions.


Solution

  • cdef double E1=(a0*c*me*s*L*sqrt(pi))/(q*(1.602*10**(-13))*sqrt(2.0)) #some code
    

    to

    cdef double E1=(a0*c*me*s*L*sqrt(pi))/(q*(1.602*10.0**(-13))*sqrt(2.0)) #some code
    

    i.e change 10 to 10.0