Version: 1.3.999 (using KDE 3.1.94 (CVS >= 20031206), compiled sources) Compiler: gcc version 3.3.1 OS: Linux (i686) release 2.4.24 Do the following easy calculation: 49.84 + 33.52 = 83.36 kcalc claims: 83.36000000000001 kcalc in kde 3.1 is working fine.
That's how floating point works. The numbers aren't absolutely precise.
Well, but I don't think that any other calculator exposes the problems of floating point math in this way. The other calculators I tried (both programs and real life) show 83.36 as the result. Also this isn't a problem of C++ because doing a "cout << double(49.84 + 33.52) << endl" also outputs 83.36.
I know, but the manipulations done internally by kcalc make it lose a bit more precision than your simple C++ program. Or, quite possibly, kcalc is just more precise in its results than iostream's operator<<(double). In any event, I agree with you it's ugly and annoying, but it's also not wrong from the floating point point of view: we're talking about a 1 in 10^19 error (meaning from a "double" point of view, they are the same number). But, yea, if possible, we should get rid of this.
Subject: Re: kcalc cannot calculate correctly Why doesn't have KDE 3.1.4 this problem? There are 16 digits selected, too. I've never seen such a problem.
As I said, it depends on the internal manipulations of the floating point variables. 83.36 and 83.36000000000001 are the *exact* same representation in 'float' and 'double' representations, but not in 'long double'. It would seem that something changed the order of the calculations/manipulations -- or of the precision of the result -- which introduced this error. Now, I don't know kcalc code and I don't know how to fix this. I want it fixed as much as you do, but I'm merely pointing out that imprecisions are always the by-product of limited precision floating point.
Can't reproduce on FreeBSD. Broken libc?
I can reproduce this when I increase the "Maximum number of digits" from the default 14 to 16. Maybe there was a reason why that default value was chosen ;-)
Fixed. QString::toDouble() only has DOUBLE precision, not LONG DOUBLE. Better not use it.
Subject: Re: kcalc cannot calculate correctly It's running fine now! Thank you very much, kind regards, Andreas Hartmann