Download Tutorial C Files H Files

dg_cos

This function calculate the cosinus of an angle in radian.

Usage

double dg_cos(double x);

Example

dg_cos(PI/2);

Source code

double dg_cos(double x)
{
    double result = 1;
    long int factorial = 1;
    int value = 1;

    x = dg_get_radian(x);
    for (int i = 2; i <= PRECISION; i += 2) {
        factorial *= (i - 1) * i;
        value *= -1;
        result += value * ((double)(1)/factorial) * dg_fpow(x, i);
    }
    return result;
}