Comment

Comment by new2yc

If you don't care about "performance":

double my_cos(double x) {

    double sum = 0;

    for (int n = 0; n < 10; n++) { // 10 terms of Taylor Series

        sum += pow(-1, n) * pow(x, 2 * n) / factorial(2 * n);

    }

    return sum;
}

Edit: code formatting

parent new2yc 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton