----- Original Message ----- From: Jan Valenta <jvalenta@mail.cern.ch> To: <roottalk@pcroot.cern.ch> Subject: Problems with precision > Hi all, > I've written and debugged numerical program in C++. It works perfectly > under NT and Linux (g++), but in ROOT there is some problem with > precision. It's obvious that the problem is in the following: > > root [60] Double_t x > root [61] x = 2.2 > (double)2.20000000000000018e+00 > root [62] Float_t s > root [63] s = 23.2 > (double)2.31999999999999993e+01 > > What to do with the garbage? Just forget it. You may do nothing with that. > How is it possible that there is "...0000018" > at the end of 2.2 and "...999993" instead of "23.20000" ? It is possible by simple reason there is NO difference beween 2.19999999999999999 and 2.2000000000000000 by means no computer code may distinguish it. It is what one should expect especially writing and debugging "numerical program" with a computer. You are using Intel CPU and 64-bit IEEE representation for real numbers Microsoft Visual C++ online docs says: " . . . Double precision values with double type have 8 bytes. The format is similar to the float format except that it has an 11-bit excess-1023 exponent and a 52-bit mantissa, plus the implied high-order 1 bit. This format gives a range of approximately 1.7E-308 to 1.7E+308 for type double. The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/-1.7E308 with at least 15 digits of precision. . . . " Which is match what you printed out perfectly. All digits beyond that have no sense. The "numerical code" must take this in account as any "numerical calculation" textbook says. Hope this helps. Valery
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET