trigonometric functions in mikro C pic compiler problem

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
208
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,763
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.

please help


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:

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

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?
please help
 

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 ]
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…