Getting exponential instead of zero in the output.

In the following simple code, I should get a zero in the output console but instead I'm getting a value 5.96046e008. Can someone please help me with this?

#include<iostream>
using namespace std;
int main()
{
int x = 1, y = 1, i, j;
float a[3][3], p;
i = x;
j = y;
p = 1.4;
a[i+1][j] = 3.5;
a[1][1] = -2.5;
a[i + 1][j] = a[x][j] * p + a[i+1][j];
cout<<a[i+1][j];

return 0;
}
Same here
http://coliru.stacked-crooked.com/a/970269e2b2b544ad

If it was 5.96046e-008, I would say that it is because of floating point precision problems.
5.96046e-008 is almost zero. The size of the error is about what you'll have to expect from using float. If you want better precision you should use double (or long double).
Topic archived. No new replies allowed.