Reputation: 163
I'm using Borland BCB6 C++ Builder. My code contains the following computation:
float result= (152*pow(cos(80),2)) + (70*pow(sin(80),2));
In debug mode, I find that this expression evaluates to about 70.992, whereas Wolfram Alpha tells me that the value should be about 72.4726. What could be the reason for this discrepancy?
Upvotes: 1
Views: 164
Reputation: 51845
In math.h
the goniometric functions use radians!!!
80.0
[deg] use 80.0*M_PI/180.0
[rad]I also usually define deg,rad
constants and use them:
const double deg=M_PI/180.0;
const double rad=180.0/M_PI;
double result= (152.0*pow(cos(80.0*deg),2.0)) + (70.0*pow(sin(80.0*deg),2.0));
Upvotes: 1