[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdeutils/kcalc
From:       Klaus Niederkrüger <kniederk () mi ! uni-koeln ! de>
Date:       2005-01-22 11:10:18
Message-ID: 20050122111018.EB4851B96C () office ! kde ! org
[Download RAW message or body]

CVS commit by kniederk: 

First fix for BUG #97561. Please check if this works for different input. But problem \
still persists in other situtations: e.g.
1.000000000005 - 1 ----> 5.00034e-11


  M +16 -2     kcalc_core.cpp   1.96
  M +4 -1      kcalctype.h   1.22


--- kdeutils/kcalc/kcalc_core.cpp  #1.95:1.96
@@ -212,5 +212,12 @@ static CALCAMNT ExecAdd(CALCAMNT left_op
 {
         // printf("ExecAdd\n");
-        return left_op + right_op;
+        CALCAMNT tmp_result = left_op + right_op;
+        // Set result to zero, when smaller than FPU-precision
+        CALCAMNT tmp_divisor = FABS(left_op) + FABS(right_op);
+        if (tmp_divisor != 0L  &&
+            FABS(tmp_result)/tmp_divisor > 2*CALCAMNT_EPSILON)
+                return tmp_result;
+        else
+                return 0L;       
 }
 
@@ -218,5 +225,12 @@ static CALCAMNT ExecSubtract(CALCAMNT le
 {
         // printf("ExecSubtract\n");
-        return left_op - right_op;
+        CALCAMNT tmp_result = left_op - right_op;
+        // Set result to zero, when smaller than FPU-precision
+        CALCAMNT tmp_divisor = FABS(left_op) + FABS(right_op);
+        if (tmp_divisor != 0L  &&
+            FABS(tmp_result)/tmp_divisor > 2*CALCAMNT_EPSILON)
+                return tmp_result;
+        else
+                return 0L;       
 }
 

--- kdeutils/kcalc/kcalctype.h  #1.21:1.22
@@ -32,4 +32,5 @@
 
 #include <limits.h>
+#include <float.h>
 #include <math.h>
 
@@ -73,4 +74,5 @@
         #define ISINF(X)        isinfl(X)
         #define STRTOD(X,Y)     strtold(X,Y)
+        #define CALCAMNT_EPSILON        LDBL_EPSILON
 #else
         #define FABS(X)         fabs(X)
@@ -97,4 +99,5 @@
         #define ISINF(X)        isinf(X)
         #define STRTOD(X,Y)     strtod(X,Y)
+        #define CALCAMNT_EPSILON        DBL_EPSILON
 #endif
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic