If you want to increase the speed, note that you can simplify the logic by unrolling the loop once, for example:
cdef double pi = 0.0 cdef double L = 1.0 while True: pi += 4.0/L - 4.0/(L+2.0) L += 4.0 print str(pi)
Also note that you do not need to invoke printing inside the loop - it probably takes ten times longer than the rest of the calculations.
Hugh bothwell
source share