Bug 106605 - 0 + 0 = nan
Summary: 0 + 0 = nan
Status: RESOLVED FIXED
Alias: None
Product: kcalc
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Klaus Niederkrüger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-01 16:33 UTC by Michael Jahn
Modified: 2005-06-08 17:21 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Fix 0 + 0 and 0 - 0 (794 bytes, patch)
2005-06-02 14:35 UTC, Nicolas Goutte
Details

Note You need to log in before you can comment on or make changes to this bug.
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