I observe that my tan(float)
function from the cmath
library is returning a negative value.
The following piece of code, when run :
#include <cmath>
....
// some calculation here gives me a value between 0.0 to 1.0.
float tempSpeed = 0.5;
float tanValue = tan(tempSpeed * 60);
__android_log_print(ANDROID_LOG_INFO, "Log Me", "speed: %f", tanValue);
Gives me this result in my Log file:
Log Me: speed `-6.4053311966`
As far as I remember
tan(0.5*60) = tan(30) = 1/squareroot(3);
Can someone help me here as in why I am seeing a negative value? Is it related to some floating point size error? Or am I doing something really dumb?
for angles with their terminal arm in Quadrant II, since sine is positive and cosine is negative, tangent is negative.
Explanation: For tan 30 degrees, the angle 30° lies between 0° and 90° (First Quadrant). Since tangent function is positive in the first quadrant, thus tan 30° value = 1/√3 or 0.5773502. . .
The two equations disclose that tan of negative angle is always equal to negative of tangent of angle. It is called tangent of negative angle identity and used as a formula in trigonometric mathematics.
Tan 30 degree is equal to 1/√3 and its exact value is 0.57735.
In C, tan
and other trigonometric functions expect radians as their arguments, not degrees. You can convert degrees to radians:
tan( 30. * M_PI / 180. ) == 0.57735026918962576450914878050196
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