Precision question

Hey guys, I have a code like this:

E = (1.0/128.0)*(cos(4.0*m)) + ((7.0/8.0)+(1.0/32.0)*(sin(4.0*m)))/(4.0*cos(4.0))*(sin(4*m)) + (pow(m,2.0))/16.0 - 1.0/128.0

where E has been specified as a double. When I execute my programme, I get a value of E = -0.309629 for m = 0.2 when my calculator shows that the actual value should be -0.29152. Is there anything wrong with my code up there or is there any code that I can use to improve the precision? Please advise, thanks!
Are you sure you get that output? I get -0.246092.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cmath>

using std::cos;
using std::sin;
using std::pow;

int main()
{
	double m = 0.2;
	double E = (1.0/128.0)*(cos(4.0*m)) + ((7.0/8.0)+(1.0/32.0)*(sin(4.0*m)))/(4.0*cos(4.0))*(sin(4*m)) + (pow(m,2.0))/16.0 - 1.0/128.0;
	std::cout << E << std::endl;
}
Last edited on
Topic archived. No new replies allowed.