summaryrefslogtreecommitdiff
path: root/docs/examples/quickstart/cythonize/integrate_cy.py
blob: 592ce8db798e2c2121cfdffb055b92bb1f169c1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
def f(x: cython.double):
    return x ** 2 - x


def integrate_f(a: cython.double, b: cython.double, N: cython.int):
    i: cython.int
    s: cython.double
    dx: cython.double
    s = 0
    dx = (b - a) / N
    for i in range(N):
        s += f(a + i * dx)
    return s * dx