-1

i have a file with a matrix n x n, for example i got these numbers:

3.162277660168379 4.110960958218893 7.58946638440411 -1.110223024625157e-016 6.715653356152327 6.224264086189961 -5.551115123125783e-016 -1.332267629550188e-015 3.107818621696872

and got code:

std::ifstream in("R.txt");
std::string line;
float B[4][4];
int u = 1, y = 1;
while (std::getline(in, line))
{
    float value;
    int y = 1;
    std::stringstream ss(line);
    while (ss >> value)
    {
        B[u][y] = value;
        cout << setprecision(16) << B[u][y] << " ";
        ++y;
    }
    cout << endl;
    ++u;
}

and get this answer when i try to output in my command line:

3.162277698516846 4.110960960388184 7.589466571807861 -1.110223024625157e-016 6.715653419494629 6.224264144897461 -5.551115123125783e-016 -1.332267629550188e-015 3.107818603515625

Has any1 any idea why my numbers are wrong readed ? from like 8th digit ? :) Thanks

1 Answers1

4

Instead of using float use double, because float will work only upto 8 decimal places

VenkatKrishna
  • 127
  • 3
  • 10