2.1.16.7.5 cos


Description

Calculate cosine of a complex value.


Calculate cosine of a double value.

Syntax

complex cos( complex z )


double cos( double x )

Parameters

z
[input] the complex value whose cosine is sought.


x
[input] Angle in radians.

Return

The cosine


The cos function returns the cosine of x.

Examples

EX1

void cos_ex1()
{
    complex        cc(0.5, 0.8);
    
    out_complex("cos = ", cos(cc));  //Result is "cos = 1.173710-0.425781i"
}


EX2

//This program computes and displays the cosine of x.
void cos_ex2()
{
    double vv;
    vv = cos(-3*PI);
    out_double("cos(-3*PI)=", vv);    //output should be cos(-3*PI)=-1
    ASSERT( is_equal(vv, -1) );

    vv = cos(0);
    out_double("cos(0)=", vv);        //output should be cos(0)=1
    ASSERT( is_equal(vv, 1) );

    vv = cos(15.5);
    out_double("cos(15.5)=", vv);    //cos(15.5)=-0.97845
    ASSERT( is_equal(round(vv,5), -0.97845) );     
}

Remark

See Also

acos

Header to Include

origin.h

Reference