Possible Duplicate:
Why doesn't sin() return the correct value here?
I am building an app which will perform math operations like sine (sinf()
) and cosine (cost()
) on floats
. Now when I tried calculating the sinus on 90 (which is 1), I got a result of 0.89... which is trebly wrong. Is there a reason why the result is so off? is there a way to improve it? I have tried using double
instead of float
and got the same answer... Is it possible it's only like than when I run it in the simulator, and will work fine on a real iPhone?
And lastly, will using a math parser like GCMathParser
or DDMathParser
improve there accuracy of the results?
Thanks, :]
The sinf
and cosf
functions use radians. You have to convert first:
float result = sinf(yourDegree / 180 * M_PI);
The problem is, it's taking the sine of 90 radians, not degrees. Try sin(M_PI_2) for 90°
The functions use radians, not degrees.
To convert degrees to radians use degrees * π / 180, so you can do something like sin( 90 * M_PI / 180 ) which reduces to π / 2 or M_PI_2
Why doesn't sin() return the correct value?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With