Unrue
12-07-2009, 10:08
Ciao ragazzi,
qualcuno sa dirmi perchè se scrivo il codice in questa maniera:
#include <iostream>
#include <iomanip>
using namespace std;
int main (){
float a = 3.21332431;
float x = 4.54223534;
float y = 6.5443432;
float first = (1.0 - x)*a + x*y;
float second = a + x*(y-a);
cout << " first "<< setprecision(20) << (1.0 - x)*a + x*y << endl;
cout << " second "<< setprecision(20) << a + x*(y-a) << endl;
return 0;
}
Ottengo i seguenti risultati:
first 18.343595218238760935
second 18.343595504760742188
Mentre se lo scrivo così:
#include <iostream>
#include <iomanip>
using namespace std;
int main (){
float a = 3.21332431;
float x = 4.54223534;
float y = 6.5443432;
float first = (1.0 - x)*a + x*y;
float second = a + x*(y-a);
cout << " first "<< setprecision(20) << first << endl;
cout << " second "<< setprecision(20) << second << endl;
return 0;
}
I risultati sono identici? : :confused:
first 18.343595504760742188
second 18.343595504760742188
qualcuno sa dirmi perchè se scrivo il codice in questa maniera:
#include <iostream>
#include <iomanip>
using namespace std;
int main (){
float a = 3.21332431;
float x = 4.54223534;
float y = 6.5443432;
float first = (1.0 - x)*a + x*y;
float second = a + x*(y-a);
cout << " first "<< setprecision(20) << (1.0 - x)*a + x*y << endl;
cout << " second "<< setprecision(20) << a + x*(y-a) << endl;
return 0;
}
Ottengo i seguenti risultati:
first 18.343595218238760935
second 18.343595504760742188
Mentre se lo scrivo così:
#include <iostream>
#include <iomanip>
using namespace std;
int main (){
float a = 3.21332431;
float x = 4.54223534;
float y = 6.5443432;
float first = (1.0 - x)*a + x*y;
float second = a + x*(y-a);
cout << " first "<< setprecision(20) << first << endl;
cout << " second "<< setprecision(20) << second << endl;
return 0;
}
I risultati sono identici? : :confused:
first 18.343595504760742188
second 18.343595504760742188