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

import cython

@cython.profile(False)
@cython.cfunc
@cython.inline
@cython.exceptval(-1.0)
def recip_square(i: cython.longlong) -> float:
    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