Search code examples
iosobjective-ciphoneipad

Why doesn't sin() return the correct value?


How do I use sin(), cos(), and tan() functions in iOS application? When I use this I didn't get the correct value. Example:

double value=sin(90);

I got value: 0.893997 but expected value: 1. How can I fix this?


Solution

  • The problem is that it's taking the sine of 90 radians, not degrees. Try sin(M_PI_2) for 90°.