| Summary: | 0 + 0 = nan | ||
|---|---|---|---|
| Product: | [Applications] kcalc | Reporter: | Michael Jahn <michael.jahn> |
| Component: | general | Assignee: | Klaus Niederkrüger <kniederk> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | nicolasg, thiago |
| Priority: | NOR | ||
| Version First Reported In: | unspecified | ||
| Target Milestone: | --- | ||
| Platform: | Compiled Sources | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | Fix 0 + 0 and 0 - 0 | ||
|
Description
Michael Jahn
2005-06-01 16:33:22 UTC
btw: I did _not_ open kcalc to calculate that for me :-) You don't want people to know you couldn't calculate 0 + 0? :-) I can confirm that, trunk 414026. The precision handling code seems to backfire, probably for 0 - 0 too. Have a nice day! Created attachment 11293 [details]
Fix 0 + 0 and 0 - 0
Can somebody try out this patch? (Not tested!)
I've tested and it has worked for me. Yes, works for me too with 3.4 branch. 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
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
|