News for hackers. Stuff that matters.
Re:Cosine Implementation in C by irchans on Friday March 31, 2023 @08:21AM (#35385976)
/* This code is silly, not super accurate, but fun /

double cos2(double x, int n) {

    double numerator = 1.0;

    double denominator = 1.0;

    double pi = 3.14159265358979323846;

    int i;

    for (i = 1; i <= n; ++i) {
        numerator   *= pow((x - n * pi / 2.0), 2);
        denominator *= pow((n * pi / 2.0), 2);
    }

    return numerator / denominator;
}

(Edit for format)

There are no comments on this comment yet.