I am new to Cython.
When I tried the Fibonacci example from Kurt Smith's book
https://library.oreilly.com/book/0636920033431/cython/toc.xhtml, I found the result is off for fib(37).
Here's the Cython code - fib.pyx:
def fib(int n):
cdef int i
cdef double a=0.0, b=1.0
for i in range(n):
a, b = a + b, a
return a
Here's test code - test_fib.py:
from fib import fib
for i in range(35, 38):
print(fib(i))
assert fib(35) + fib(36) == fib(37)
The output is:
9227465.0
14930352.0
24157816.0
Traceback (most recent call last):
File "test_fib.py", line 7, in <module>
assert fib(35) + fib(36) == fib(37)
AssertionError
This issue happens with:
1. distutils and cythonize
2. pyximport
This works correctly with:
1. Interactive Cython with IPython’s %%cython Magic
2. On OS X (using distutils and cythonize)