rounding errors?

hi all, i recently replaced the following calculation, which is a sum of products:

r1.sumNCp = O2.N*O2.Cp + N2.N*N2.Cp + H2O.N*H2O.Cp + CO.N*CO2.Cp + CO2.N*CO2.Cp;

with this call:

r1.sumNCp = r1.sumNCpcalc(O2ptr,N2ptr,H2Optr,COptr,CO2ptr);

to this function inside the class definition that r1 comes from:

double sumNCpcalc(CHEMICAL *_O2ptr,CHEMICAL *_N2ptr,CHEMICAL *_H2Optr,CHEMICAL *_COptr,CHEMICAL *_CO2ptr)
{
return (_O2ptr-> N*_O2ptr->Cp
+ _N2ptr-> N*_N2ptr->Cp
+ _H2Optr->N*_H2Optr->Cp
+ _COptr-> N*_COptr->Cp
+ _CO2ptr->N*_CO2ptr->Cp);}

with my class declarations in main.cpp being

CHEMICAL O2, *O2ptr; O2ptr = &O2;
CHEMICAL N2, *N2ptr; N2ptr = &N2;
CHEMICAL H2O, *H2Optr; H2Optr = &H2O;
CHEMICAL CO, *COptr; COptr = &CO;
CHEMICAL CO2, *CO2ptr; CO2ptr = &CO2;

my results, while very very very close, down to the 5th digit, are not quite the same... any idea why this might be? both sumNCp and sumNCpcalc are declared as doubles.

thanks very much for any advice!

Look up "What every computer scientist should know about floating point arithmetic" on google, then
read Goldberg's paper.
Topic archived. No new replies allowed.