When I tried to print sin() and cos() of 60 degrees, 30 degrees,s, and 45 degrees in a for loop, for some iterations, the output is showing strange values in the range of e-006. I am using DevC++ to run the code. Why this happens and how can I rectify this? A screenshot of the output is attached with this. The error occurs only once in every 100-200 iterations.
output screenshot
compiler settings:
compiler





#include<iostream>
#include<cmath>
using namespace std;
int main()
{
for(double i=0;i<100;i++)
{
cout<<i<<" : "<<cos((M_PI/180.0)*60.0)<<" : "<<cos((M_PI/180.0)*45.0)<<" : "<<sin((M_PI/180.0)*45.0)<<" : "<<sin((M_PI/180.0)*30.0)<<"\n";
}
}
The output is like:
i cos(60) cos(45) sin(45) sin(30)
**********************************************
0 : 0.5 : 0.707107 : 0.707107 : 0.5
1 : 0.5 : 0.707107 : 0.707107 : 0.5
2 : 0.5 : 0.707107 : 0.707107 : 0.5
3 : 0.5 : 0.707107 : 0.707107 : 0.5
4 : 0.5 : 0.707107 : 0.707107 : 0.5
5 : 7.62939e-006 : 0.707107 : 0.707107 : 0.5
6 : 0.5 : 0.707107 : 0.707107 : 0.5
7 : 0.5 : 0.707107 : 0.707107 : 0.5
8 : 0.5 : 0.707107 : 0.707107 : 0.5
Thank you.