# trigonometric functions in mikro C pic compiler problem

Status
Not open for further replies.

#### Noman Yousaf

##### Full Member level 4
hi
i want to perform some trigonometric functions in mikroC like get the value of sin90, cos30 etc.
i wrote this code but when i run it and watch RAM, values are not correct.
even when i do it with float, incorrect values occur.

Code C - [expand]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
long val3;

void calculate (void)
{
val3=sin(90);
}

void main()
{

while(1)
{
calculate();
}
}

Last edited by a moderator:

#### andre_luis

##### Super Moderator
Staff member
It is expected an argument in radians, not in degrees.
You must multiply it by a factor of ( 2*PI / 360 ).

#### Noman Yousaf

##### Full Member level 4
It is expected an argument in radians, not in degrees.
You must multiply it by a factor of ( 2*PI / 360 ).

it shows in RAM is 8.5090 ok?
when it is multiplied to 2*pi/360 (0.01744), answer is 0.1483
where as its answer must be 0.707

- - - Updated - - -

can anyone tell the simplest way to get sin value in degrees?
what does mean by the following?
i got it from help

sin
Prototype

double sin(double f);

Description Function returns the sine of f in radians. The return value is from -1 to 1.

Example doub = sin(PI/2.); // doub = 1.000000

how can i use it for my purpose?

#### andre_luis

##### Super Moderator
Staff member
when it is multiplied to 2*pi/360 (0.01744), answer is 0.1483
where as its answer must be 0.707

You're having some mistake:

• 45*( 2*pi/360 ) = 0,785
• sin ( 0,785 ) = 0,7068... [ operation in rads ]

Noman Yousaf

Points: 2