summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/profiling_tutorial/calc_pi_3.py
blob: df3dfa3a1ba155f18d28b6281a44386f84e4d034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# cython: profile=True
import cython

@cython.cfunc
@cython.inline
@cython.exceptval(-1.0)
def recip_square(i: cython.longlong) -> cython.double:
    return 1. / (i * i)

def approx_pi(n: cython.int = 10000000):
    val: cython.double = 0.
    k: cython.int
    for k in range(1, n + 1):
        val += recip_square(k)
    return (6 * val) ** .5