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

List:       koffice-devel
Subject:    patch for kspread precision problem
From:       Ariya Hidayat <ariya () tf ! itb ! ac ! id>
Date:       2002-08-19 5:01:52
[Download RAW message or body]

Sometimes precision problem in KSpread is caused because certain numbers
are parsed as integer. This patch solves the problem, the idea is simple:
for sequence of more than 8 digits, parse it as floating point because
it'll be overflow in long integer. This fixes, among others, bug #40150.

Please review.


["kspread_precision.patch" (TEXT/PLAIN)]

loading global options from .cvsrc
  arg 0: cvs
  arg 1: -z4
  arg 2: -q
  arg 3: diff
  arg 4: scanner.ll

getopt_long result: 122 z
getopt_long result: 113 q
Index: scanner.ll
===================================================================
RCS file: /home/kde/koffice/lib/koscript/scanner.ll,v
retrieving revision 1.17
diff -u -3 -p -r1.17 scanner.ll
--- scanner.ll	2002/05/09 23:04:40	1.17
+++ scanner.ll	2002/08/17 09:44:59
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <qstring.h>
+#include <string.h>
 
 #include "koscript_parsenode.h"
 #include "koscript_types.h"
@@ -41,6 +42,11 @@ static bool s_kspread;
 KLocale* s_koscript_locale = 0;
 static KLocale* s_defaultLocale = 0;
 
+#define PARSE_NUM(yytext) \
+  if( strlen( yytext ) < 8 ) \
+  { yylval._int = ascii_to_longlong( 10, yytext ); return T_INTEGER_LITERAL; } else \
+  { yylval._float = ascii_to_longdouble( yytext ); return T_FLOATING_PT_LITERAL; }
+
 static KScript::Long ascii_to_longlong( long base, const char *s )
 {
   KScript::Long ll = 0;
@@ -347,8 +353,7 @@ KScript_Identifier      [_a-zA-Z][a-zA-Z
                         }
 <REGEXP_GROUP>{Digit}   {
                                 yy_pop_state();
-                                yylval._int = ascii_to_longlong( 10, yytext );
-                                return T_INTEGER_LITERAL;
+                                PARSE_NUM(yytext);
                         }
 <REGEXP_GROUP>.         {
                                 yy_pop_state();
@@ -420,8 +425,7 @@ from                    return T_FROM;
                           return T_FLOATING_PT_LITERAL;
                         }
 <KSPREAD>{KSpread_Int_Literal1} {
-                          yylval._int = ascii_to_longlong( 10, yytext );
-                          return T_INTEGER_LITERAL;
+                          PARSE_NUM( yytext );
                         }
 
 <PLAIN>{Plain_Float_Literal1} |
@@ -433,8 +437,7 @@ from                    return T_FROM;
                           return T_FLOATING_PT_LITERAL;
                         }
 <PLAIN>{Plain_Int_Literal} {
-                          yylval._int = ascii_to_longlong( 10, yytext );
-                          return T_INTEGER_LITERAL;
+                          PARSE_NUM( yytext );
                         }
 
 {Oct_Literal}           {

_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.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