# Calculating Sin/Cosine

This is a discussion on Calculating Sin/Cosine within the C Programming forums, part of the General Programming Boards category; Hi, I'd like help getting started writing my own routines to calculate sin and cos. But I really don't know ...

1. ## Calculating Sin/Cosine

Hi,
I'd like help getting started writing my own routines to calculate sin and cos. But I really don't know where to begin..

This is what I know:

sin(x) = x (for very small x)
cos(x) = 1 (for very small x)
sin(x) = 2*sin(x/2)*cos(x/2)
cos(x) = (cos(x/2))^2 - (sin(x/2))^2 (where "^" means "power")

This is what I've done so far:

while (x >= 0.0001){ //first checks to see if x is really small
mysinx == 2*(x div 2) * mycosx(x/2);
}
while(x = 1){
mycos(x) == ((x/2))^2 - (mysinx(x/2))^2;
}

Thanks, Josh

2. This looks like a recursive exercise

There are two cases
1. the limiting case - sin(x) = x (for very small x)
2. the reducing case - sin(x) = 2*sin(x/2)*cos(x/2)

Code:
```double sin ( double x ) {
if ( x < 0.000001 ) {
return x;  // case 1
} else {
return 2 * sin( x/2 ) * cos ( x/2 ); // case 2
}
}```
Shrug....