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

List:       koffice-devel
Subject:    Re: ROUNDUP in kspread
From:       Hasso Tepper <hasso () estpak ! ee>
Date:       2001-08-01 23:55:21
[Download RAW message or body]

Daniel Naber wrote:
> Now I get it, you can revert my "fix". But the problem you are
> experiencing is not just a "bug", it's just the way computer
> represent numbers. It's all described here:
> http://mindprod.com/jglossf.html#F, then search for "Floating
> Point".

Yes, I know it already although it took time for me to think it
out :)). But problem remains. 

I just fixed roundup function in cvs because fix Laurent commited was 
just wrong. But this fix is not 100% correct either and probably will 
fail in platforms where float and double have same lenght. But here 
in i386 all roundup testcases are ok now. 

Ceil function can't be fixed same way, I'm afraid. If I will find 
time in weekend, I will try to find out what's going on with other 
functions and will add failing cases to the testcase.

I will attach patch I commited.

regards,

Hasso
["kspread.patch" (text/x-diff)]

Index: kspread_interpreter.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_interpreter.cc,v
retrieving revision 1.96
diff -u -3 -p -r1.96 kspread_interpreter.cc
--- kspread_interpreter.cc	2001/08/01 13:32:30	1.96
+++ kspread_interpreter.cc	2001/08/01 23:46:09
@@ -2537,11 +2537,12 @@ static bool kspreadfunc_roundup( KSConte
                 return false;
         digits=args[1]->intValue();
         }
-
-  if (floor(args[0]->doubleValue()) == args[0]->doubleValue())
+  // This is not correct solution for problem with floating point numbers and \
probably +  // will fail in platforms where float and double lenghts are same.
+  if (floor((float)(args[0]->doubleValue()*pow(10,digits))) == \
(float)(args[0]->doubleValue()*pow(10,digits)))  result = args[0]->doubleValue();
   else
-      result=floor(args[0]->doubleValue()*pow(10,digits))/pow(10,digits);
+      result=floor(args[0]->doubleValue()*pow(10,digits)+1)/pow(10,digits);
   context.setValue( new KSValue( result) );
 
   return true;


_______________________________________________
Koffice-devel mailing list
Koffice-devel@master.kde.org
http://master.kde.org/mailman/listinfo/koffice-devel


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

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