Bug 106605

Summary: 0 + 0 = nan
Product: [Applications] kcalc Reporter: Michael Jahn <michael.jahn>
Component: generalAssignee: Klaus Niederkrüger <kniederk>
Status: RESOLVED FIXED    
Severity: normal CC: nicolasg, thiago
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Fix 0 + 0 and 0 - 0

Description Michael Jahn 2005-06-01 16:33:22 UTC
Version:            (using KDE KDE 3.4.1)
Installed from:    Compiled From Sources

Calculating 0 + 0 results in nan.
Expected result: 0 :-)
Comment 1 Michael Jahn 2005-06-01 16:36:09 UTC
btw: I did _not_ open kcalc to calculate that for me :-)
Comment 2 Thiago Macieira 2005-06-02 06:00:45 UTC
You don't want people to know you couldn't calculate 0 + 0? :-)

I can confirm that, trunk 414026.
Comment 3 Nicolas Goutte 2005-06-02 14:33:51 UTC
The precision handling code seems to backfire, probably for 0 - 0 too.

Have a nice day!
Comment 4 Nicolas Goutte 2005-06-02 14:35:46 UTC
Created attachment 11293 [details]
Fix 0 + 0 and 0 - 0 

Can somebody try out this patch? (Not tested!)
Comment 5 Thiago Macieira 2005-06-07 07:29:38 UTC
I've tested and it has worked for me.
Comment 6 Michael Jahn 2005-06-08 11:57:45 UTC
Yes, works for me too with 3.4 branch.
Comment 7 Nicolas Goutte 2005-06-08 16:36:56 UTC
SVN commit 423478 by goutte:

Fix 0+0 and 0-0 (The result is now again 0 not NaN)
CCBUG:106605

Can anybody port it back to KDE 3.4.x (and close the bug thereafter)?


 M  +7 -0      kcalc_core.cpp  


--- trunk/KDE/kdeutils/kcalc/kcalc_core.cpp #423477:423478
@@ -213,6 +213,9 @@
 	// printf("ExecAdd\n");
 	CALCAMNT tmp_result = left_op + right_op;
 
+	if (!tmp_result)
+		return 0;
+
 	// When operating with floating point numbers the following
 	// effect can happen: 1.0000001 + (-1.0) gives 1.0000232e-6
 	// instead of 1e-6. This looks very bad on a calculator (to
@@ -233,6 +236,10 @@
 {
 	// printf("ExecSubtract\n");
 	CALCAMNT tmp_result = left_op - right_op;
+
+	if (!tmp_result)
+		return 0;
+
 	// When operating with floating point numbers the following
 	// effect can happen: 1.0000001 + (-1.0) gives 1.0000232e-6
 	// instead of 1e-6. This looks very bad on a calculator (to
Comment 8 Thiago Macieira 2005-06-08 17:21:54 UTC
SVN commit 423486 by thiago:

Backporting commit 423478 by goutte to the branch.

This fixes the 0+0 and 0-0 glitch (0+0 != NaN).

BUG:106605


 M  +7 -0      kcalc_core.cpp  


--- branches/KDE/3.4/kdeutils/kcalc/kcalc_core.cpp #423485:423486
@@ -213,6 +213,9 @@
 	// printf("ExecAdd\n");
 	CALCAMNT tmp_result = left_op + right_op;
 
+	if (!tmp_result)
+		return 0;
+
 	// When operating with floating point numbers the following
 	// effect can happen: 1.0000001 + (-1.0) gives 1.0000232e-6
 	// instead of 1e-6. This looks very bad on a calculator (to
@@ -233,6 +236,10 @@
 {
 	// printf("ExecSubtract\n");
 	CALCAMNT tmp_result = left_op - right_op;
+
+	if (!tmp_result)
+		return 0;
+
 	// When operating with floating point numbers the following
 	// effect can happen: 1.0000001 + (-1.0) gives 1.0000232e-6
 	// instead of 1e-6. This looks very bad on a calculator (to